webpacker Uncaught Error: Module build failed / Cannot find module 'babel-plugin-syntax-dynamic-import'

webpacker Uncaught Error: Module build failed / Cannot find module 'babel-plugin-syntax-dynamic-import'

在使用我的 Rails 5.2.4 应用程序设置 webpacker 时,我将这个错误引入了我的浏览器控制台:Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-plugin-syntax-dynamic-import' from '/Users/me/code/project' - Did you mean "@babel/syntax-dynamic-import"

@babel/syntax-dynamic-import不是真正的包,这是什么意思?查看 index.js 文件,我没有看到 babel-plugin-syntax-dynamic-import。此外,所述插件存储在node_modules/@babel/babel-plugin-syntax-dynamic-import中。阅读 后,我确定我所有的 babel 包都在版本 7 上。除了 babel-loader v8,因为 v7 正在寻找不正确的依赖项。

据我所知,我的 package.json 看起来还不错:

{
  "dependencies": {
    "@babel/core": "^7.11.6",
    "@babel/plugin-proposal-class-properties": "^7.10.4",
    "@babel/plugin-proposal-object-rest-spread": "^7.11.0",
    "@babel/plugin-syntax-dynamic-import": "^7.8.3",
    "@babel/preset-env": "^7.11.5",
    "@babel/preset-react": "^7.10.4",
    "@rails/webpacker": "5.2.1",
    "babel-loader": "^8.1.0",
    "micromodal": "^0.4.6",
    "prop-types": "^15.6.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "semantic-ui": "2.4.2",
    "uppy": "^1.21.1"
  },
  "devDependencies": {
    "webpack-dev-server": "^3.11.0"
  },
  "version": "0.0.0"
}

此外,我的根目录中没有剩余的 .babelrc 文件。

解决方案是将 babel-loader@8.1.0 降级为 babel-loader@8.0.6