Babel 7.0和webpack失败

时间:2018-11-13 05:22:57

标签: webpack babel babel-loader

我正在尝试运行通天塔

npx webpack -p --env production && babel src --out-dir dist --source-maps inline

我看到该错误显示在命令的后面。

运行命令后出现的错误:

Error: Requires Babel "^7.0.0-0", but was loaded with "6.25.0". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.
at throwVersionError (/mnt/c/Users/Arkadiy/Desktop/project4/node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
at Object.assertVersion (/mnt/c/Users/Arkadiy/Desktop/project4/node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
at _default (/mnt/c/Users/Arkadiy/Desktop/project4/node_modules/@babel/plugin-proposal-decorators/lib/index.js:35:7)
at /mnt/c/Users/Arkadiy/Desktop/project4/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
at Function.memoisePluginContainer (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
at Function.normalisePlugin (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
at /mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at OptionManager.init (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transform (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/lib/babel/util.js:50:22)
at Object.compile (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/lib/babel/util.js:59:12)
at write (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/lib/babel/dir.js:21:21)
at handleFile (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/lib/babel/dir.js:43:7)
at /mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/lib/babel/dir.js:61:9
at Array.forEach (<anonymous>)
at handle (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/lib/babel/dir.js:59:29)
at Array.forEach (<anonymous>)
at module.exports (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/lib/babel/dir.js:69:15)
at Object.<anonymous> (/mnt/c/Users/Arkadiy/AppData/Roaming/npm/node_modules/babel-cli/lib/babel/index.js:129:1)
at Module._compile (module.js:662:30)

这是我的config.js信息:

DevDependencies:

"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"eslint": "^5.9.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-flowtype": "^2.50.3",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^21.27.2",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"flow-bin": "^0.82.0",
"flow-typed": "^2.5.1",
"jest": "^23.6.0",
"jest-cli": "^23.6.0",

依赖项:

"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.5",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.5",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2"

Webpack配置

module: {
rules: [
  {
    test: /\.jsx?$/,
    exclude: /node_modules/,
    use: 'babel-loader',
  },
  {
    test: /\.css$/,
    use: ['style-loader', 'css-loader'],
  },
],

1 个答案:

答案 0 :(得分:0)

尝试运行npm cache clean并使用npm install重新安装,然后重新构建。