我正在尝试将项目从使用karma
,phantomJs
迁移到jest
,但是我无法正确获取配置文件。我不断收到以下错误:
FAIL test/unit/components/SomethingWentWrong/SomethingWentWrong.spec.js
● Test suite failed to run
Cannot find module 'npm:react@16.4.1/index.js' from 'react@16.4.1.js'
> 1 | module.exports = require("npm:react@16.4.1/index.js");
| ^
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
at Object.<anonymous> (jspm_packages/npm/react@16.4.1.js:1:18)
这是我的babel
和jest
配置的摘要。
... rest of code
"devDependencies": {
"@babel/core": "^7.0.0-beta.56",
"babel-jest": "^23.4.2",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"jest": "^23.4.2",
"react-test-renderer": "^16.4.2"
},
"jest": {
"verbose": true,
"testURL": "http://localhost/",
"transform": {
"^.+\\.(jsx|js)?$": "<rootDir>/node_modules/babel-jest"
},
"collectCoverageFrom": [ "!**/node_modules/**" ]
},
"babel": {
"presets": [
[
"env",
{
"loose": true,
"debug": false,
"targets": {
"browsers": [
"last 3 versions"
]
}
}
],
"react"
]
}
... rest of code
如果有人可以帮助我和/或为我指明正确的方向,我不明白这是什么问题?非常感谢
答案 0 :(得分:0)
我实际上发现了问题所在,因为该项目正在处理jspm
和npm
的依赖关系,由于某些原因,即使执行了npm install my_package
或jspm install npm:my_package
。快速浏览node_folder
,确认即使软件包出现在package.json
npm cache verified
和新的jspm install npm: my_package
解决了该问题