当前位置:   article > 正文

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

module build failed (from ./node_modules/babel-loader/lib/index.js): error:

在使用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
  • 1

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

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

相关配置修改:

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

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

更新:

"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@babel/preset-react": "^7.7.4",
"babel-loader": "^8.0.6",
  • 1
  • 2
  • 3
  • 4

babel配置修改为:

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

2 . 降级版本,执行命令

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

相关配置降级到6.0版本:

"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-loader": "^7.1.5",
  • 1
  • 2
  • 3
  • 4

babel配置修改为 :

presets: [
“env”,“react”
]

npm网址:babel-loader

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/450811
推荐阅读
相关标签
  

闽ICP备14008679号