react 脚本和 jest 版本 24.7.1 之间的冲突

kev*_*man 5 javascript node.js reactjs jestjs

使用“create-react-app”创建反应应用程序后,到目前为止一切都已成功。我做了一个有效的反应项目。但是现在我想用玩笑来实现单元测试。

使用 npm 安装: 'npm install --save-dev jest' 然后运行: npm ls jest 我注意到 react-script 正在寻找一个明显更旧的 jest 版本。

包.json:

"dependencies": {
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-redux": "^6.0.0",
"react-scripts": "2.1.5",
"redux": "^4.0.1"
},

"devDependencies": {
"jest": "^24.7.1"
},

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject"
}
Run Code Online (Sandbox Code Playgroud)

npm ls 开玩笑的结果:

+-- jest@24.7.1
`-- react-scripts@2.1.5
  `-- jest@23.6.0
Run Code Online (Sandbox Code Playgroud)

npm启动错误:

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix 
locally.

The react-scripts package provided by Create React App requires a         
dependency:

"jest": "23.6.0"

Don't try to install it manually: your package manager does it 
automatically.
However, a different version of jest was detected higher up in the tree:

C:\Users\userName\sample js codes\redux\songs\node_modules\jest (version: 
24.7.1)
Run Code Online (Sandbox Code Playgroud)

是否有解决此依赖版本问题的解决方案?

Pat*_*und 6

Create-react-app内置了 Jest,无需另外安装。

您现在有版本冲突,因为您另外安装了它。要修复它,请将您的更改还原到package.json