【发布时间】:2019-04-03 19:16:53
【问题描述】:
好的,这几天我一直在为此烦恼。所以我最后会向 StackOverflow 的优秀人员寻求急需的帮助:)
Here is the error I'm getting => Identifier 'global' has already been declared
And it seems to not recognize the require keyword
所以目前,50% 的测试套件通过了。
它似乎只在调用 redux reducer 的测试中抛出。因为几乎所有失败的测试的错误都是一样的。
这是我目前的babel.config.js
module.exports = function(api) {
const isTest = api.env('test')
const presets = [
isTest && [
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
[
'next/babel',
{
'preset-env': {},
'transform-runtime': {},
'styled-jsx': {},
'class-properties': {},
},
],
].filter(Boolean)
const plugins = ['babel-plugin-styled-components']
return {
presets,
plugins,
sourceType: 'unambiguous',
}
}
并且依赖关系在
"devDependencies": {
"@babel/core": "^7.3.3",
"@babel/preset-env": "^7.3.1",
"@cypress/snapshot": "^2.0.1",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.1.0",
"babel-plugin-styled-components": "^1.10.0",
"cross-env": "^5.2.0",
"cypress": "^3.1.5",
"eslint": "^5.14.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.2.2",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.0.1",
"husky": "^1.3.1",
"jest": "^24.1.0",
"jest-canvas-mock": "^1.1.0",
"jest-dom": "^3.1.2",
"next-progressbar": "^1.0.0",
"nock": "^10.0.6",
"node-sass": "^4.11.0",
"nodemon": "^1.18.10",
"prettier": "1.16.1",
"pretty-quick": "^1.10.0",
"react-testing-library": "^5.9.0",
"redux-mock-store": "^1.5.3",
"require-all": "^3.0.0"
}
【问题讨论】:
-
您是否可能缺少“babel-jest”依赖项? jestjs.io/docs/en/getting-started#using-babel
-
正如之前的评论所指出的,如果没有minimal reproducible example 来重现问题,则很难提供帮助。
-
@GoGoris 我已经包含了完整的 devDependencies,babel-jest 也是最新版本。
-
@g00glen00b 同意,这可能信息太少,将设置一个代码框来重现它。