开玩笑的错误,需要Babel“ ^ 7.0.0-0”,但已加载“ 6.26.3”

时间:2019-03-19 10:27:46

标签: reactjs testing jestjs babel babel-core

我运行的每个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安装软件包时,才会出现此错误。那是什么问题呢?我做错了什么? 附言我不想使用yarn install

这是我paskage.json的通行证,玩笑和酵素相关部分:

{
  "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",
  },
}

1 个答案:

答案 0 :(得分:0)

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

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

为jest 23加载兼容版本的babel