【发布时间】:2021-09-04 14:06:55
【问题描述】:
我的文件结构如下所示
-root
-node_modules
-server.js
-package.json
-client
-node_modules
-package.json
我有一个以 react 作为前端的 nodejs 应用程序。我可以很好地测试客户端,因为 react-scripts 内置了 jest。当我尝试在后端的根目录中安装 jest 时,尝试构建客户端文件夹时遇到 jest 不兼容问题。
The react-scripts package provided by Create React App requires a dependency:
"babel-jest": "^26.6.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:
/Users/user/project/node_modules/babel-jest (version: 27.0.2)
执行删除 package.json 的过程不起作用。原因是因为在根目录中安装任何版本的 jest 都会在客户端之前看到。我试图安装 jest@26.6.0 以获得确切的版本,但它安装了 jest@26.6.x。我删除了 node_modules 文件夹,从中删除了 jest 和 jest-cli,然后重新安装。我需要根目录 node_modules 上的 Jest 来测试我的服务器端代码。
我可以安装 jest 并运行测试,但是在客户端运行 yarn build 会引发兼容性错误。
我可以卸载 jest 以在客户端文件夹中运行 yarn build,但随后在服务器端运行 npm test 将不起作用,因为 jest 不存在。
有谁知道获取 EXACT jest@26.6.0 包的方法,或者在管理包方面我在这里缺少什么。
【问题讨论】:
标签: node.js reactjs jestjs babeljs