Jest 测试 Babel 错误:插件/预设文件不允许导出对象 [英] Jest Test Babel Error: Plugin/Preset files are not allowed to export objects

查看:28
本文介绍了Jest 测试 Babel 错误:插件/预设文件不允许导出对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是最新的(2017 年 12 月) 依赖项堆栈.当我用 Jest 尝试同构反应测试时,测试服不断失败并出现以下错误:

I'm using a very up-to-date (December 2017) stack of dependencies. As I try-out isomorphic react tests with Jest, the test suit keeps failing with the following error:

* Test suite failed to run
[BABEL] /__tests__/router.test.js: Plugin/Preset files are not allowed to
export objects, only functions.

这是我的依赖项:

"dependencies": {
    "axios": "^0.17.1",
    "babel-polyfill": "^6.26.0",
    "cors": "^2.8.4",
    "express": "^4.16.2",
    "react": "^16.1.1",
    "react-dom": "^16.1.1",
    "react-router-dom": "^4.2.2"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0-beta.35",
    "babel-cli": "^6.26.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-eslint": "^8.0.2",
    "babel-jest": "^22.0.1",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "enzyme": "^3.2.0",
    "enzyme-adapter-react-16": "^1.1.0",
    "enzyme-to-json": "^3.2.2",
    "eslint": "^4.11.0",
    "eslint-plugin-react": "^7.5.1",
    "html-webpack-plugin": "^2.30.1",
    "jest": "^21.2.1",
    "nodemon": "^1.11.0",
    "parallelshell": "^3.0.2",
    "react-test-renderer": "^16.2.0",
    "regenerator-runtime": "^0.11.1",
    "supertest": "^3.0.0",
    "webpack": "^3.8.1",
    "webpack-dev-server": "^2.9.4"
  },
  "peerDependencies": {
    "babel-core": "^7.0.0-0"
  }

.babelrc :

{
  "presets": [
    "env",
    "react",
  ]
}

有没有人知道为什么 Jest 不会运行?

Does anyone have any insights as to why Jest won't run?

推荐答案

babel bridge 旨在涵盖 6 到 7 之间的任何问题

babel bridge is meant to cover any issues between 6 and 7

这 100% 不是桥包所做的.它所做的只是允许使用 babel-core 的工具传递到 @babel/core.整个包是这一行代码.

That is 100% not what the bridge package does. All it does is allow tools that use babel-core to pass through to @babel/core. The entire package is this single line of code.

如果你使用 @babel/core,你需要使用适用于 Babel 7 的插件.这意味着 babel-preset-react 应该改为 @babel/preset-react@babel/preset-env 相同,你的 .babelrc 应该是:

If you are using @babel/core, you need to use plugins that work on Babel 7. That means babel-preset-react should be changed to @babel/preset-react and same for @babel/preset-env and your .babelrc should be:

{
  "presets": [
    "@babel/env",
    "@babel/react",
  ]
}

同理,babel-polyfill 应该是 @babel/polyfill.

这些都没有得到很好的记录,因为 Babel 7 仍然是一个不稳定的测试版.

None of this is well documented yet because Babel 7 is still an unstable beta.

这篇关于Jest 测试 Babel 错误:插件/预设文件不允许导出对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆