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

标签 javascript node.js reactjs jestjs

在使用“create-react-app”创建了一个 React 应用程序之后,事情一直很成功。我做了一个工作 react 项目。但是现在我正在 Jest 实现单元测试。

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

package.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"
}

npm ls jest 结果:

+-- jest@24.7.1
`-- react-scripts@2.1.5
  `-- jest@23.6.0

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)

有解决这个依赖版本问题的方案吗?

最佳答案

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

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

关于javascript - react 脚本和 jest 版本 24.7.1 之间的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55630841/

相关文章:

css - 如何根据变量的输出在我的 React 网络应用程序中设置组件的宽度

mysql - 将问号字符转义为 NodeJS 中 MySQL 查询的占位符

node.js - 如何在 typescript 中导入 recursive-readdir

reactjs - 如何修复自定义 Hook 中的 "useEffect has a missing dependency"

javascript - 如何在不拉伸(stretch) three.js 前景的情况下增加视角

javascript - 如何将 Svg Circle 放在页面中间

javascript - 在 Openshift 上热部署 node.js 应用程序时究竟发生了什么?

javascript - 表单验证事件中不会出现失败消息

node.js - 如何将 .then 方法制作为 async.waterfall Node js

javascript - React Uncaught TypeError : search. map 不是函数