当我尝试使用Webpack 4和Babel 7启动我的React应用程序时,错误弹出。
Error: Plugin/Preset files are not allowed to export objects, only functions. In C:\Users\Yifeng\reactApp\node_modules\babel-preset-react\lib\index.js
at createDescriptor (C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:178:11)
at C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:109:29)
at createPresetDescriptors (C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:101:10)
at C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:58:96
at cachedFunction (C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\caching.js:32:19)
at presets (C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:29:84)
at mergeChainOpts (C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\config-chain.js:320:26)
at C:\Users\Yifeng\reactApp\node_modules\@babel\core\lib\config\config-chain.js:283:7
我在网上查找了此错误的其他情况,并发现了https://github.com/babel/babel/issues/6808,但是在我添加了@babel/preset-env
和@babel/preset-react
之后,问题仍然存在。
package.json
`
{
"name": "firefly",
"version": "1.0.0",
"description": "a simple mobile app",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production"
},
"keywords": [
"firefly"
],
"author": "Yifeng Lin",
"license": "ISC",
"dependencies": {
"core-js": "^3.5.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"webpack": "^4.41.3",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.0"
},
"devDependencies": {
"@babel/core": "^7.7.5",
"@babel/preset-env": "^7.7.6",
"@babel/preset-react": "^7.7.4",
"babel-loader": "^8.0.6",
"html-webpack-plugin": "^3.2.0"
},
"repository": {
"type": "",
"url": ""
},
"bugs": {
"url": ""
},
"homepage": ""
}