Reputation:
[Update]: It seems that the issue can be temporarily fixed by copying the package-lock.json
from a working branch and pasting it into the non-working branch.
This doesn't make sense to me though as the package-lock.json
should not affect the npm install
.
I am having a strange issue when trying to npm install. First I begin on my master branch and run an npm install
and my application works with no issues. Then I switch to a different branch and git pull
from my master branch. I then try to run npm install
and after this when I try to run my application I get the following error:
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:
"webpack": "4.41.2"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
/Users/t.dammon/work/cpax/cpax-react/node_modules/webpack (version: 4.41.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 "webpack" 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:
5. 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.
6. Check if /Users/t.dammon/work/cpax/cpax-react/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
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!
I have tried deleting my node modules and my package-lock before running npm install
. I have also tried all of the troubleshooting steps listed in the error message.
I have also compared my package-lock files in the non-working branch and the working branch (both of which have just run npm install) and it seems like the non-working branch is updating some dependency versions higher than the working branch.
What I find really interesting is that if I run npm start
in my working branch and pull up my app and then switch branches I can than stop and start my app in the non-working branch (so long as I don't run npm install
).
So my conclusion is that something funky is going on with npm install
in my branch which isn't happening elsewhere, but I really can't figure out what exactly would cause this problem.
One other additional detail, when I run npm install
in a working branch I will have a vulnerability to audit, while the npm install
in the non-working branch will not uncover a vulnerability.
Upvotes: 1
Views: 1475
Reputation: 31
I've also experienced this exact error and it took a while to figure out what was wrong - the provided error instructions didn't work, running npm outdated
and getting all dependencies to the latest didn't work. Even swapping out the contents of the package.json file with a brand new one via npx creat-react-app
wasn't working for me.
Solution: I checked the parent folder my project was stored in and found it also had a node_modules
folder. Removing this folder cleared the error for me. This is a bit odd, as the removed folder was outside of my project folder, but it looks like NPM is working its way up the directory tree, looking for any node_modules
folders.
Upvotes: 1