jestjs - Jest 与 Babel ^7.0.0-beta.51 问题

标签 jestjs babeljs yarnpkg babel-jest

我遵循了你推荐的一切,让 Babel 7 与 Jest 一起工作。
我安装了@babel/corebabel-core .还是不行。

{
  "devDependencies": {
    "@babel/cli": "^7.0.0-beta.51",
    "@babel/core": "^7.0.0-beta.51",
    "@babel/node": "^7.0.0-beta.51",
    "@babel/plugin-transform-modules-commonjs": "^7.0.0-beta.51",
    "@babel/preset-flow": "^7.0.0-beta.51",
    "babel-core": "^7.0.0-beta.51",
    "jest-cli": "^23.1.0"
  }
}

yarn jest
yarn run v1.9.0-20180612.1255
$ /Users/m/Desktop/k/node_modules/.bin/jest
 FAIL  packages/services/src/Client/__tests__/Client.js
  - Test suite failed to run

    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.

      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-transform-modules-commonjs/lib/index.js:51:7)
      at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
          at Array.map (<anonymous>)

最佳答案

在 Jest GitHub 问题上看到您的问题——我认为是您提出的问题,但我最终通过 create-react-app repo 解决了这个问题。并了解他们如何整合 Jest。具体来说, packages/react-scripts/package.json 文件有你需要的东西。
"@babel/core": "7.0.0-beta.46", "@babel/runtime": "7.0.0-beta.46", "autoprefixer": "8.5.0", + "babel-core": "7.0.0-bridge.0", "babel-eslint": "8.2.3", "babel-jest": "22.4.3",
添加带有 + 的行,或更改您拥有的版本,您应该会很好。

关于jestjs - Jest 与 Babel ^7.0.0-beta.51 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50837535/

相关文章:

javascript - mock axios get 并在 Jest 中发布

javascript - Jest 测试上下文/监视在函数外部创建的模拟变量(类级别)

node.js - 如何在 Jest 中测试来自 Express 的响应数据

javascript - 条件渲染在 React 映射循环中不起作用

javascript - yarn 找不到模块(html-to-text)

reactjs - 在 Jest 中使用模拟无法找到模块 '../request' 错误

reactjs - 无法在react-native-web 上运行webpack-dev-server。错误: You may need an appropriate loader to handle this file type

javascript - Webpack - 代码分割 : split library into it's own file

symfony - 找不到错误命令 "encore"。 (单独的后端 webpack)

node.js - 在 gitlab ci 中找不到 yarn 命令