33

Today i decided to start react native cli project. Everything works great since i want to add new lib of course using npm . So i ran npm install ... . And this command always stuck on Image

idealTree: timing idealTree Completed in 3440ms

And nothing happened. So i tried to ran

npm install --verbose

And again stuck on the same place. Also clear cache npm cache clear --force and nothing happened again. I don'n know how to fix this

Hristo Ivanov
  • 405
  • 1
  • 3
  • 7

7 Answers7

31

I have had npm install freeze on me numerous times, lately. I'm not sure of the cause. When that happens I follow these steps:

  1. Kill the npm install process with ctrl+c.
  2. Delete node_modules. If there are files that you cannot delete because they are currently in use, that may mean that the npm install process was not successfully stopped. Try opening Task Manager and ending all nodejs and terminal processes. If this fails, restart your pc and then delete node_modules
  3. Clean cache and reinstall node_modules with npm cache clean --force && npm i
PhantomSpooks
  • 2,877
  • 2
  • 8
  • 13
  • 5
    Probably this is overkill, npm cache virtually never needs cleaning. An answer below mentions `stopping the dev server` (that is probably locking some node_modules folder), should work just fine. In this answer's second step OP does the same by `killing nodejs processes`. – Preda7or Apr 19 '22 at 12:56
  • 1
    When I was doing this I would stop the server and npm install would still freeze. Sometimes doing a full reboot would not be enough to stop it from freezing. I later found out my hard drive was failing and maybe that had something to do why I had to do this overkill – PhantomSpooks Sep 24 '22 at 01:00
  • Closed my vscode and that allowed me to delete the node_modules allowing the install to complete. – Owen Allen Jan 15 '23 at 20:27
16

This has happened to me a few times before and all I had to do was kill my dev server before running npm install.

Hope that helps as well!

soygreg
  • 171
  • 1
  • 3
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31470069) – Barry Michael Doyle Apr 11 '22 at 08:58
  • 4
    Perhaps "stop the server before attempting to run `npm install`" would fit the format? This solution worked for me without removing `node_modules`, possibly because it still involved "ending all nodejs and terminal processes" from the accepted answer. – dcwaters Apr 12 '22 at 14:49
  • This does give an answer to the question. Trying to install modules while Metro is running is a common cause of this problem on Windows. – Glenn Maynard Feb 12 '23 at 22:38
8

I had the same issue on node latest version v18.8.0 and npm v8.18.0, I just downgraded to node 16.6 using nvm and it worked fine.

Ahmed Imam
  • 1,315
  • 2
  • 19
  • 42
  • 3
    This! I've been searching constantly and it ended up being my node / npm version. I used nvm versions lts, v19, and v18, and nothing worked but went to v16.18.1 and now my npm install is working again... No idea why – SNYDERHAUS Nov 09 '22 at 02:27
  • Downgrading isn't a great solution especially as the codebase uses elements baked into node 18 – d36williams Apr 20 '23 at 13:37
  • I had the same issue and it worked when I downgraded node version. Here, we're using libraries that are compatible with node 16. Previously it didn't work for node v18. Maybe downgrade to v16 to install libraries and upgrade it to v18. – sarath chandra Jul 03 '23 at 10:22
3

For me, the issue was that I had node running for a separate project. Terminating the other node process fixed the issue.

BoltKey
  • 1,994
  • 1
  • 14
  • 26
0

I also faced this problem and the solution was simple by stopping all the "nodejs terminals" that are working outside. When you stop nodeJS Terminals running in the background, it will complete the current installation process. enter image description here

  • The screenshot doesn't seem to add value here. Additionally, this seems to be the same as other answers - consider adding more detail to yours too distinguish it as unique, if possible. – ryanwebjackson May 13 '22 at 13:05
0

When you want to add package on your project it is better to stop server before adding new package. I had same problem but after doing this it is solved.

0

When i opened my package.json i saw '~2.2.1' in front of react-native-gesture-handler which probably means that it was notinstalled properly Just close all terminals and then open task manager and kill all the processes corresponding to NodeJS. Then install it again. Hopefully it will resolve.

royam
  • 9
  • 1