我正在使用 Babel-7、Webpack 创建反应应用程序。当我尝试在生产模式下构建应用程序时,出现以下错误。
/home/mr3/projects/my-project/node_modules/webpack-cli/bin/cli.js:231
throw err;
^
Error: Cannot find module '@babel/runtime/core-js/get-iterator'
at Function.Module._resolveFilename (module.js:543:15)
at Function.Module._load (module.js:470:25)
at Module.require (module.js:593:17)
at require (/home/mr3/projects/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/home/mr3/projects/my-project/node_modules/preload-webpack-plugin/build/index.js:5:44)
at Module._compile (/home/mr3/projects/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (/home/mr3/projects/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/home/mr3/projects/my-project/config/webpack/webpack.prod.config.js:5:30)
at Module._compile (/home/mr3/projects/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (/home/mr3/projects/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at WEBPACK_OPTIONS (/home/mr3/projects/my-project/node_modules/webpack-cli/bin/convert-argv.js:115:13)
at requireConfig (/home/mr3/projects/my-project/node_modules/webpack-cli/bin/convert-argv.js:117:6)
at /home/mr3/projects/my-project/node_modules/webpack-cli/bin/convert-argv.js:124:17
at Array.forEach (<anonymous>)
at module.exports (/home/mr3/projects/my-project/node_modules/webpack-cli/bin/convert-argv.js:122:15)
at yargs.parse (/home/mr3/projects/my-project/node_modules/webpack-cli/bin/cli.js:228:39)
at Object.parse (/home/mr3/projects/my-project/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
at /home/mr3/projects/my-project/node_modules/webpack-cli/bin/cli.js:206:8
at Object.<anonymous> (/home/mr3/projects/my-project/node_modules/webpack-cli/bin/cli.js:505:3)
at Module._compile (module.js:649:30)
我试图通过添加最新版本的 Babel 和 Webpack 来解决这个问题。删除node_modules
并重新安装。问题依然存在。
如何解决此错误?
以下是我的 package.json 文件中的依赖项。
{
"dependencies": {
"@material-ui/core": "^1.5.1",
"@material-ui/icons": "^3.0.2",
"react": "^16.8.5",
"react-dom": "^16.8.5",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"react-router-redux": "^5.0.0-alpha.9",
"redux": "^4.0.0"
},
"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-decorators": "^7.4.0",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-modules-commonjs": "^7.4.3",
"@babel/plugin-transform-react-constant-elements": "^7.2.0",
"@babel/polyfill": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/preset-react": "^7.0.0",
"@types/html-webpack-plugin": "^3.2.0",
"add-asset-html-webpack-plugin": "^2.1.3",
"babel-eslint": "^8.2.6",
"babel-loader": "^8.0.5",
"babel-plugin-dynamic-import-node-babel-7": "^2.0.7",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-react-intl": "^3.0.1",
"babel-plugin-styled-components": "^1.10.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
"babel-plugin-transform-runtime": "^6.23.0",
"@babel/runtime": "^7.4.3",
"camelcase": "^5.0.0",
"chunk-manifest-webpack-plugin": "^1.1.2",
"circular-dependency-plugin": "^5.0.2",
"clean-webpack-plugin": "^0.1.19",
"exports-loader": "^0.7.0",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"offline-plugin": "^5.0.5",
"preload-webpack-plugin": "3.0.0-beta.1",
"style-loader": "^0.22.0",
"url-loader": "^1.0.1",
"webpack": "^4.16.5",
"webpack-auto-inject-version": "^1.1.0",
"webpack-bundle-analyzer": "^2.13.1",
"webpack-chunk-hash": "^0.6.0",
"webpack-cli": "^3.3.0",
"webpack-dev-middleware": "^3.1.3",
"webpack-hot-middleware": "^2.22.3"
}
}