-2

I've tried installing jest for testing react apps

After installing them with yarn, I'm unable to start my react app any way

I'm getting the below message, but it didn't work.

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:

"babel-jest": "^24.9.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:

C:\Users\YV\node_modules\babel-jest (version: 27.0.5)

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. 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.
  2. Delete node_modules in your project folder.
  3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

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. This may help because npm has known issues with package hoisting which may get resolved in future versions.

  2. Check if C:\Users\YV\node_modules\babel-jest is outside your project directory. For example, you might have accidentally installed something in your home folder.

  3. Try running npm ls babel-jest in your project folder. This will tell you which other package (apart from the expected react-scripts) installed babel-jest.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

yvdevy
  • 25
  • 2
  • 8
  • Does this answer your question? [NPM start returns error, "There might be a problem with the project dependency tree"](https://stackoverflow.com/questions/56528222/npm-start-returns-error-there-might-be-a-problem-with-the-project-dependency-t) – ponury-kostek Jul 06 '21 at 19:50
  • no, it didn't work – yvdevy Jul 06 '21 at 20:56

2 Answers2

1

I just had the same issue and fixed it. So, you probably installed jest globally on accident. In doing so, it likely ended up installed inside of users/yourname/node-modules/. If you can pull up a terminal, try doing a cd into node-modules from your home folder then do a ls -a. If you see babel-jest, do a rm -r babel-jest and rm -r jest. This fixed the problem for me. I'm running Linux, but the same strategy should work on Windows (not sure if the commands are exactly the same).

imdp
  • 11
  • 1
  • Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 09 '21 at 05:47
  • This was exactly my problem. However for me it was only type annotations for jest that was installed globally. So removed /users//node_modules/@types/jest and that worked. Specific method for removal was by `cd /users//node_modules/@types/`and then `rm -drf jest` – Graunephar Sep 05 '22 at 08:45
0

You probably installed a different global (npm install -g) version that is currently conflicting with the one you installed in your project.

You can quite literally delete the folder babel-jest inside C:\Users\YV\node_modules\ and try again. I would assume you're doing this by using create-react-app. Rest assured that Jest is already part of the installed dependencies (hence the message pointing to package-lock.json).

  • tried that, not working, even if jest is not a dependency of the project, it's getting added during npm install – yvdevy Jul 06 '21 at 20:46
  • If that and `npm uninstall -g babel-jest`, followed by `npm install` in the project, I really wouldn't know, then. I had the exact same issue a year ago and solve it like that. If ignoring that is an option, I'd recommend create a new file called ".env" and insert `SKIP_PREFLIGHT_CHECK=true` for you to be able to work on it without issues for the meantime. – Rodrigo M. F. Castilho Jul 06 '21 at 21:16