webpack 中 Module build failed (from ./node_modules/babel-loader/lib/index.js): 的错误解决

在使用webpack打包中出现以下错误:

Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions.

1. 原因:

出现错误是由于babel的版本冲,
有两种解决方式:

版本更换:
1 . babel-loader 8.x | babel 7.x (升级版本)

npm install -D babel-loader @babel/core @babel/preset-env webpack

2 . babel-loader 7.x | babel 6.x (降级版本)

npm install -D babel-loader@7 babel-core babel-preset-env webpack

相关配置修改:

1 . 升级版本,执行命令:

npm install -D babel-loader @babel/core @babel/preset-env @babel/preset-react webpack

更新:

"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@babel/preset-react": "^7.7.4",
"babel-loader": "^8.0.6",

babel配置修改为:

presets: [
“@babel/env”, “@babel/react”
]

2 . 降级版本,执行命令

npm install -D babel-loader@7 babel-core babel-preset-env babel-preset-react webpack

相关配置降级到6.0版本:

"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-loader": "^7.1.5",

babel配置修改为 :

presets: [
“env”,“react”
]

npm网址:babel-loader

你可能感兴趣的:(webpack,vue,npm插件收藏使用,webpack)