While working on a project, I needed to use npm packages and I received a strange error while trying to use them. I ended up with the same error for yarn commands. Now, I had used npm some time back and did not have any issues.
Below is the error I ended up with each time I tried a npm or a yarn command.
Error: Cannot find module ‘C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js’
Solutions I tried and did not work for me:
- Reinstall npm.
- Repair npm
- Update my .npmrc file
- Restart the system! – that’s what the IT service center asks you to do first thing when you contact them….
What solved the problem?
So, obviously I tried and find the file mentioned in the error in my node.js folder. I obviously found it and banged my head on the wall!
Finally, I tried to trace the file by exact path when I noticed that the following part was extra in there –
The correct path should have been “C:\Program Files\nodejs\node_modules\npm\bin\ npm-cli.js”
And that’s wen I went back and looked at my environment variables and found following culprit!!
All I had to do was delete this entry, restart my command line and BINGO!
Finally, the moral of the story is – the system variable for npm should be as below:
Now, The question is how did that erroneous entry landed in my system variables? There could be multiple reasons for it like:
- I manually added it and obviously do not remember!
- At some point of time, my system some how had multiple versions of node.js
- It got corrupted while updating the node.js versions.
Hope this helps someone in need. Till then,
Happy Coding 😊