在使用我的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文件。
发布于 2020-09-17 08:54:37
解决方案是将babel-loader@8.1.0降级到babel-loader@8.0.6
https://stackoverflow.com/questions/63929138
复制相似问题