简体   繁体   English

react + node应用程序中的babel-jest版本冲突

[英]babel-jest version conflict in react + node application

Im trying to run jest tests on server side of my application but the babel-jest version is conflicting with react's babel-jest version.我试图在我的应用程序的服务器端运行 jest 测试,但 babel-jest 版本与 react 的 babel-jest 版本冲突。

and when i run my application i get this error.当我运行我的应用程序时,我得到了这个错误。

when i do 'npm ls babel-jest' i get this当我做“npm ls babel-jest”时,我明白了

babel-jest@24.9.0 -- jest@26.0.1 -- @jest/core@26.0.1 -- jest-config@26.0.1 -- babel-jest@26.0.1 babel-jest@24.9.0 -- jest@26.0.1 -- @jest/core@26.0.1 -- jest-config@26.0.1 -- babel-jest@26.0.1

Follow all of the steps that the error output gave your, but instead of the step 3 that's given (remove it from dependencies), do this:按照错误 output 给您的所有步骤操作,不是给出的步骤 3(从依赖项中删除它),请执行以下操作:

  1. go into package.json , locate jest in dependencies and/or devDependencies , and replace the version number you find with 24.9.0 go 到package.json中,在dependencies和/或devDependencies中找到jest ,并将找到的版本号替换为24.9.0
cmds-ui-operations@0.1.2 /builds/ielts-cmds/IELTS-CMDS-ui-grp/cmds-ui-operations
+-- react-scripts@3.4.1
| +-- babel-jest@24.9.0
| `-- jest@24.9.0
|   `-- jest-cli@24.9.0
|     `-- jest-config@24.9.0
|       `-- babel-jest@24.9.0 deduped
`-- ts-jest@26.4.3
  `-- jest@26.6.1
    `-- @jest/core@26.6.1
      `-- jest-config@26.6.1
        `-- babel-jest@26.6.1

[32;1m$ npm run build[0;m

cmds-ui-operations@0.1.2 build react-scripts build cmds-ui-operations@0.1.2 build react-scripts build

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.这可能不是 Create React App 中的错误,而是您需要在本地修复的错误。

The react-scripts package provided by Create React App requires a dependency: Create React App 提供的 react-scripts package 需要依赖:

"babel-jest": "^24.9.0" "babel-jest": "^24.9.0"

Don't try to install it manually: your package manager does it automatically.不要尝试手动安装:您的 package 管理器会自动安装。 However, a different version of babel-jest was detected higher up in the tree:但是,在树的较高位置检测到不同版本的 babel-jest:

/builds/ielts-cmds/IELTS-CMDS-ui-grp/cmds-ui-operations/node_modules/babel-jest (version: 26.6.1) /builds/ielts-cmds/IELTS-CMDS-ui-grp/cmds-ui-operations/node_modules/babel-jest(版本:26.6.1)

Manually installing incompatible versions is known to cause hard-to-debug issues.众所周知,手动安装不兼容的版本会导致难以调试的问题。

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an.env file in your project.如果您希望忽略此检查,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。 That will permanently disable this message but you might encounter other issues.这将永久禁用此消息,但您可能会遇到其他问题。

To fix the dependency tree, try following the steps below in the exact order:要修复依赖关系树,请尝试按确切顺序执行以下步骤:

  1. Delete package-lock.json (not package.json.) and/or yarn.lock in your project folder.删除项目文件夹中的 package-lock.json(不是 package.json。)和/或 yarn.lock。
  2. Delete node_modules in your project folder.删除项目文件夹中的 node_modules。
  3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.从项目文件夹中 package.json 文件中的依赖项和/或 devDependencies 中删除“babel-jest”。
  4. Run npm install or yarn, depending on the package manager you use.运行 npm install 或 yarn,具体取决于您使用的 package 管理器。

In most cases, this should be enough to fix the problem.在大多数情况下,这应该足以解决问题。 If this has not helped, there are a few other things you can try:如果这没有帮助,您可以尝试其他一些方法:

  1. If you used npm, install yarn ( http://yarnpkg.com/ ) and repeat the above steps with it instead.如果您使用 npm,请安装 yarn ( http://yarnpkg.com/ ) 并用它重复上述步骤。 This may help because npm has known issues with package hoisting which may get resolved in future versions.这可能会有所帮助,因为 npm 已知 package 提升问题,这些问题可能会在未来的版本中得到解决。

  2. Check if /builds/ielts-cmds/IELTS-CMDS-ui-grp/cmds-ui-operations/node_modules/babel-jest is outside your project directory.检查 /builds/ielts-cmds/IELTS-CMDS-ui-grp/cmds-ui-operations/node_modules/babel-jest 是否在您的项目目录之外。 For example, you might have accidentally installed something in your home folder.例如,您可能不小心在主文件夹中安装了一些东西。

  3. Try running npm ls babel-jest in your project folder.尝试在项目文件夹中运行 npm ls babel-jest。 This will tell you which other package (apart from the expected react-scripts) installed babel-jest.这将告诉您哪些其他 package(除了预期的 react-scripts)安装了 babel-jest。

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an.env file in your project.如果没有其他帮助,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。 That would permanently disable this preflight check in case you want to proceed anyway.如果您仍然想继续,这将永久禁用此预检检查。

For anyone coming across this in future - I ran into this same problem when installing Jest in the server folder containing a nested client created by CRA.对于将来遇到此问题的任何人-在包含由 CRA 创建的嵌套客户端的服务器文件夹中安装 Jest 时,我遇到了同样的问题。 My solution was to match the version of Jest that is installed by CRA in my server side package.json.我的解决方案是匹配 CRA 在我的服务器端 package.json 安装的 Jest 版本。

In my case, on the client side I was using: "react-scripts": "4.0.3"就我而言,在客户端我使用的是:“react-scripts”:“4.0.3”

Which has the following dependency: "jest": "26.6.0"它具有以下依赖关系:“jest”:“26.6.0”

So in the server package.json I required the same version of jest.所以在服务器 package.json 我需要相同版本的笑话。 Deleted server node_modules & package-lock and did clean npm install.删除了服务器 node_modules & package-lock 并清理了 npm 安装。

Now both server & client are using the same version of jest (& nested deps).现在服务器和客户端都使用相同版本的 jest(和嵌套的 deps)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM