首页 > 解决方案 > 开玩笑的错误,需要 Babel “^7.0.0-0”,但加载的是“6.26.3”

问题描述

对于我运行的每个 Jest 测试套件,我都会收到此错误:

Requires Babel "^7.0.0-0", but was loaded with "6.26.3". 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.

但奇怪的是,只有当我尝试通过npm install. 那么问题是什么?我做错了什么?PS我不想用yarn install

这是我paskage.json的 babel、jest 和酶相关部分:

{
  "devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.3.4",
    "@babel/plugin-proposal-class-properties": "^7.2.3",
    "@babel/plugin-proposal-decorators": "^7.2.3",
    "@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.2.0",
    "@babel/plugin-transform-object-assign": "^7.2.0",
    "@babel/plugin-transform-runtime": "^7.2.0",
    "@babel/preset-flow": "^7.0.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^23.6.0",
    "babel-loader": "8.0.4",
    "babel-plugin-react-docgen": "^2.0.0",
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.7.1",
    "jest": "^23.6.0",
    "jest-enzyme": "^7.0.1",
    "jest-pnp-resolver": "1.0.1",
    "jest-resolve": "23.6.0",
  },
}

标签: reactjstestingjestjsbabeljsbabel-core

解决方案


Jest 23 不支持 @babel/core 7。要么升级到支持 babel 7 的 Jest 24 要么运行

npm install --save-dev babel-core@7.0.0-bridge.0

为 jest 23 加载兼容版本的 babel


推荐阅读