Jest Test Babel错误:不允许插件/预设文件导出对象 [英] Jest Test Babel Error: Plugin/Preset files are not allowed to export objects
问题描述
我正在使用最新的(2017年12月)依赖项堆栈.当我尝试使用Jest进行同构反应测试时,测试服始终失败并显示以下错误:
* 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为何无法运行有任何见解吗?
babel bridge旨在涵盖6到7之间的所有问题
那不是桥包所做的100%.它所做的只是允许使用babel-core
的工具传递到@babel/core
.整个软件包是这行代码. /p>
如果您使用的是@babel/core
,则需要使用可在Babel 7上运行的插件.这意味着babel-preset-react
应该更改为@babel/preset-react
,对于@babel/preset-env
应该相同,而.babelrc
应该是:>
{
"presets": [
"@babel/env",
"@babel/react",
]
}
类似地,babel-polyfill
应该是@babel/polyfill
.
由于Babel 7仍是不稳定的Beta,因此尚未对此进行充分的记录.
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.
Here are my dependencies:
"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",
]
}
Does anyone have any insights as to why Jest won't run?
babel bridge is meant to cover any issues between 6 and 7
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.
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",
]
}
Similarly, babel-polyfill
should be @babel/polyfill
.
None of this is well documented yet because Babel 7 is still an unstable beta.
这篇关于Jest Test Babel错误:不允许插件/预设文件导出对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!