【问题标题】:Incompatibile Jest Versions with react-scripts与 react-scripts 不兼容的 Jest 版本
【发布时间】: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


    【解决方案1】:

    要安装精确的软件包版本,请使用以下语法:

    npm install --save [package-name]@[version-number]

    所以在你的情况下,使用:

    npm install --save jest@26.6.0

    【讨论】:

      猜你喜欢
      • 2022-07-20
      • 2020-08-27
      • 1970-01-01
      • 2020-01-12
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 2022-06-25
      • 2021-03-23
      相关资源
      最近更新 更多