报错信息
ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/babel-preset-stage-0/lib/index.js
at createDescriptor (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
at /Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
at presets (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
at mergeChainOpts (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-chain.js:320:26)
at /Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-chain.js:283:7
at buildRootChain (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-chain.js:120:22)
at loadPrivatePartialConfig (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/partial.js:85:55)
当出现这种错误的时候,就说明最新的babel
已经不是这样配置的了。
解决问题:
首先,卸载之前安装的
npm uni babel-core babel-loader babel-plugin-transform-runtime -D
npm uni babel-core babel-loader babel-plugin-transform-runtime -D
然后,再进行如下的安装:
npm i babel-loader @babel/core @babel/runtime @babel/preset-env @babel/plugin-proposal-class-properties @babel/plugin-transform-runtime -D
另外配置也要修改 在.babelrc文件中 要配置成
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties"
]
}