在使用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
中。阅读this后,我确保所有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文件。
答案 0 :(得分:1)
解决方案是将babel-loader@8.1.0
降级为babel-loader@8.0.6