Webpack无法编译错误 babel-core版本问题

问题描述

我正在尝试运行react项目。编译时出现错误

模块构建失败:错误:需要Babel“ ^ 7.0.0-0”,但已加载“ 6.25.0”。如果您确定拥有@ babel / core的兼容版本,则可能是您的构建过程中加载了错误的版本

检查此错误的堆栈跟踪,以查找第一个未提及“ @ babel / core”或“ babel-core”的条目,以了解调用Babel的情况。

当前这是我的package.json:

“依赖项”:{

"@babel/core": "^7.11.1","@babel/plugin-proposal-class-properties": "^7.10.4","@babel/plugin-proposal-object-rest-spread": "^7.11.0","@babel/preset-env": "^7.11.0","@babel/preset-react": "^7.10.4","babel-cli": "6.24.1","babel-loader": "^7.1.1",

}

以下是webpack.config.js文件中的条目:

模块:{

rules: [{
  loader: 'babel-loader',test: /\.js$/,exclude: /node_modules/
}

我卸载了babel-core v6.25.0并安装了@ babel / core v7.10.4,但仍然出现相同的错误。有什么办法可以解决这个问题?

解决方法

I had the same mistake. Installed the following versions fixed:

"babel-core": "^6.26.0","babel-loader": "^7.1.2","babel-preset-env": "^1.6.0",