找不到模块 'babel-core' 并且安装了“@babel-core”

Cannot find module 'babel-core' and "@babel-core" is installed

我在 运行 npm run dev

时收到此错误

./src/app.js 中的错误 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js): 错误:找不到模块 'babel-core' 需要堆栈:

即使我安装的是@babel-core 而不是 babel-core

这是我的 .babelrc

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ]
}

这是我的 package.json

{
  "name": "react-setup-tutorial",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack --mode=development",
    "build": "webpack --mode=production",
    "dev": "webpack-dev-server"
  },
  "browser": {
    "crypto": false,
    "fs": false,
    "path": false,
    "os": false,
    "net": false,
    "stream": false,
    "tls": false
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.14.6",
    "@babel/preset-env": "^7.14.7",
    "@babel/preset-react": "^7.14.5",
    "babel-loader": "^7.1.5",
    "css-loader": "^3.5.2",
    "sass-loader": "^8.0.2",
    "style-loader": "^1.1.3",
    "webpack": "^4.42.1",
    "webpack-cli": "^3.3.11",
    "webpack-dev-server": "^3.11.2"
  },
  "dependencies": {
    "@types/node": "^15.12.5",
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  },
  "engines": {
    "npm": ">3"
  }

even that I installed @babel-core not babel-core

@babel/core 是要使用的那个,但它只适用于 "babel-loader": "^8.x",所以你的 package.json 目前是错误的,因为它有

"babel-loader": "^7.1.5",

如果您安装了最新版本,您应该可以开始使用了。