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

标签 javascript jestjs babeljs babel-jest

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

● Test suite failed to run

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

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.

  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>)

Test Suites: 8 failed, 8 total

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": {
    "@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",

最佳答案

你需要同时拥有 babel-core@^7@babel/core@^7 以及 babel-jest@latest , 尝试添加

yarn add babel-jest babel-core@^7.0.0-0

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

关于javascript - 需要 Babel "^7.0.0-0",但加载了 "6.26.0",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50620775/

相关文章:

underscore.js - 开 Jest 无法加载下划线

javascript - Jest Enzyme 如何对包装组件的存在进行浅层测试

babeljs - 如何配置 babel/preset-env 以包含 core-js URLSearchParams polyfill?

javascript - 更改视频标签源video.js

javascript - 在 flot 图中显示一个值的时间

vue.js - Nuxt.js 中的 Jest 全局插件

javascript - 在 Lerna 单体仓库中使用助手

jestjs - Stenciljs 和 Jest。意外的 token "export"

javascript - 如何测试 Grunt 插件

javascript - 动画左不能在页面滚动上工作