需要Babel" ^ 7.0.0-0",但已加载" 6.26.0"

时间:2018-05-31 09:18:02

标签: javascript jestjs babel babel-jest

我已将我的应用迁移到babel 7 beta版,除了测试外,一切似乎都有效。我想我已经阅读了所有内容,但我仍然收到此错误:

  

●测试套件无法运行

Requires Babel "^7.0.0-0", but was loaded with "6.26.0". If you are sure you have a compatible version of @babel/core, it is likely
     

您的构建过程中的某些内容正在加载错误的版本。   检查此错误的堆栈跟踪以查找第一个条目   没有提到" @ babel / core"或" babel-core"看什么是   叫巴贝尔。

  at throwVersionError (node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
  at Object.assertVersion (node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
  at _default (node_modules/@babel/plugin-proposal-class-properties/lib/index.js:81:7)
  at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
      at Array.map (<anonymous>)
     

测试套房:8次失败,总共8次

babelrc

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "@babel/preset-flow"
  ],
  "plugins": [
    ["module-resolver", {
      "alias": {
        "static": "./static",
        "common": "./src/common",
        "data": "./src/data"
      }
    }],
    ["styled-jsx/babel", { "plugins": ["styled-jsx-plugin-sass"] }],
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-syntax-dynamic-import"
  ]
}

devDependencies

  "devDependencies": {
    "@babel/cli": "^7.0.0-beta.49",
    "@babel/core": "^7.0.0-beta.49",
    "@babel/plugin-proposal-class-properties": "^7.0.0-beta.49",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0-beta.49",
    "@babel/preset-env": "^7.0.0-beta.49",
    "@babel/preset-flow": "^7.0.0-beta.49",
    "@babel/preset-react": "^7.0.0-beta.49",
    "babel-core": "^7.0.0-0",
    "babel-eslint": "8.2.3",
    "babel-loader": "^8.0.0-beta",
    "babel-plugin-module-resolver": "^3.1.1",
    "clean-webpack-plugin": "^0.1.19",
    "copy-webpack-plugin": "^4.5.1",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    ...

jest.config.js

module.exports = {
  rootDir: '<rootDir>/../../',
  collectCoverageFrom: ['src/**/*.(jsx|js)'],
  moduleNameMapper: {
    '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '<rootDir>/tests/fileMock.js',
  },
  setupTestFrameworkScriptFile: '<rootDir>/tests/setupTests.js',
};

我用命令运行它:

"test": "jest --config tests/jest.config.js",

2 个答案:

答案 0 :(得分:6)

您需要同时拥有{{1}和babel-core@^7@babel/core@^7,并尝试添加

babel-jest@latest

如此处https://github.com/facebook/jest/issues/5525

所述

答案 1 :(得分:0)

就我而言,事实证明我已经npm i -D babel-jest显式安装了此软件包。