How to figure out why does the npm hang? - npm

I'm suffering from the infamous npm install (update) hanging problem.
So far I found following recipes:
cleaned the cache: npm cache clean
deleted npm_modules in my project
set the registry to plain http (http://registry.npmjs.org/): npm config set registry http://registry.npmjs.org/
used --loglevel=verbose flag with npm install
increased number of connections as described here:
Increasing the maximum number of tcp/ip connections in linux
Yet it still hangs. The position at which it hangs seems to be random. It can be
npm verb get saving gulp-traceur to /home/me/.npm/registry.npmjs.org/gulp-traceur/.cache.json; or when installing npm verb afterAdd /home/me/.npm/q/0.9.7/package/package.json the last package downloaded is really random.
The versions are:
npm info using npm#2.7.5
npm info using node#v0.12.0
So the question is if there is anything else I can do about it?

I don't know if you have the same problem as I did but I can't make a comment to your question because I have not enough reputation.
Today somebody found solution to my similar problem. You can check it here:

Sometimes you need to use --force command to make sure the cache is cleaned:
npm cache clean --force.
Maybe related to this issue.

I tried all the above. I use homebrew and had to uninstall node / npm.
This worked for me:
brew install nvm
nvm install node
Afterwards npm started working again for me.

Related

NPM stuck on idealTree: timing idealTree

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
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:
Kill the npm install process with ctrl+c.
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
Clean cache and reinstall node_modules with npm cache clean --force && npm i
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!
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.
For me, the issue was that I had node running for a separate project. Terminating the other node process fixed the issue.
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.
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
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.

How to fix timeout for packages on `npm install`?

When I run npm install it seems to work fine until part way installing packages. It seems to have no problem with the first half, but then after a while it will fail to be able to reach other packages. I just get the repeating errors, eg:
npm http request GET https://registry.npmjs.org/react-hot-loader
npm info attempt registry request try #3 at 6:43:34 AM
npm http request GET https://registry.npmjs.org/react-tap-event-plugin
npm info attempt registry request try #3 at 6:43:34 AM
npm http request GET https://registry.npmjs.org/react-test-renderer
etc.
It will continue to do this for an hour and and then the install will fail.
The install breaks at a different package each time so I don't think it's a problem with a particular file.
I can access these files fine with my browser and curl.
My work has a firewall but this domain is whitelisted.
Would anyone know what I could do to get this to work or what could be causing it?
If it's about the timing problem you should find a speed solutions for npm install.
So you can try these faster command than npm install :
pnpm install %70 faster
or
npm install --no-audit 15% faster
or
npm install --prefer-offline --no-audit 15% faster
check this article for details : speeding up npm install
You can override the max and min timeout in ~/.npmrc.
// npm config ls -l
// add these 2 lines in ~/.npmrc
fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000
If your internet connection is the problem, try increasing the timeout:
npm config set timeout 6000000
The value is a 32-bit int.
If it's still relevant or maybe for other people of interest: For me it helped, deleting the package.lock file and running npm cache clean --force.
It might not be your case, but I had issues with a package being hosted at github with the repo url being only with git protocol (port 9418 not usually open on firewall).
Once added that to the firewall I could npm install without issues.
You can view the repository url with:
$ npm view zone.js repository.url
git://github.com/angular/angular.git
I saw an answer earlier that can resolve your problem by overriding the max and min timeout in ~/.npmrc file, but some didn't understand how to do it.
First go to the nodejs folder - for me it's located at ( Y:\Program Files\nodejs )
Open the node_modules folder.
Then npm folder.
Select (.npmrc) file + right click and open it with any text editor you want.
Finally add these 2 lines and click Ctrl+S
fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000
.npmrc file after modification
npm cache clean --force
npm install --force
It works fine.
If you are on windows, try running vscode as administrator, it worked for me, I tried npm config delete https-proxy , npm config delete proxy and , tried deleting node_modules, and package.lock.json and ran npm cache clean --force but at last ran vscode as adminitrator before deleting node_modules and package.lock.json, it worked
I solved the timeout issue by executing these commands:
rm package-lock.json
npm i

VS Code terminal fails to use npm version from nvm

I'm using nvm on my Terminal and successfully installed node 10.2.1, which also installed npm 6.1.0. However, when I go to my VS Code editor, it gives me warnings in the integrated terminal for:
npm WARN npm npm does not support Node.js v10.2.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4,6, 7, 8, 9.
Turns out, it is actually using npm 5.5.1 (npm -v).
I check to see what's up with that and tried to dig further and eventually used: which npm on both integrated terminal and Mac's CLI.
Mac's Terminal shows:
/Users/Aiz/.nvm/versions/node/v10.2.1/bin/npm
VS Code's Terminal shows:
/usr/local/bin/npm. Which is interesting, because if you do which node in this terminal, it results in the appropriate /Users/Aiz/.nvm/versions/node/v10.2.1/bin/node.
I'm not sure how to get my VS Code terminal to point to the appropriate npm install through nvm. Not sure if it helps, but I checked npm get prefix and npm -g bin to find /Users/Aiz/.nvm/versions/node/v10.2.1. The only difference I'm finding is where each terminal is using npm from.
I ended up looking through VS Code issues on GitHub and came across something relevant to NVM and node issues. It fixed my issue since the underlying cause was the same.
Essentially what happened is that I had a global install of node before that I removed prior to using NVM but hadn't removed my global install of npm. This was causing conflicts in VS Code's terminal (not Mac's terminal). In order to fix this, you essentially have to find the symlink for which npm and remove the node_modules and npm associated recursively.
Here's the link you'll need: https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched.
Don't forget to restart your editor after.
Another solution is to implement this. https://medium.com/#kinduff/automatic-version-switch-for-nvm-ff9e00ae67f3
Basically, nvm will check for a .nvmrc and switch or default each time you go to a new directory in shell.
It does have a dependency on zsh.
The fix for me on Ubuntu:
A.) sudo apt-get remove nodejs npm
B.) Removed lines in my .bashrc that added the npm package directory to the path.
C.) Restart VS Code.
I doubt step A is necessary. But B and C certainly are.

How can I remove the npm registry from my machine?

I published a module to npm. When I uninstall it and try to reinstall it, this is always done from a cache ( it is done even if I'm not connected to the internet, I just get a warning ). I would like to try if my module installs correctly from the remote npm repository on a fresh npm registry.
I tried to remove Node.js and reinstall it, but it does not help. There is no "npm" in the list of my applications that I could remove, only Node.js is listed. This is on a Windows 10 machine.
Where is the npm registry located and how can I remove it entirely?
You have to clean your NPM cache and then clear your registry using the below commands.
npm cache clean
npm config delete registry
Thanks
npm config delete registry
This worked for me

npm install node-inspector always suspends

I recently study node and try to use npm to install node-inspector globally. But it always suspends here as following pic
I have changed the registry config for times, but it still doesn't work. Anyone can help? TAT
When npm install is stuck, you can increase verbosity of the output from install.
npm config set loglevel verbose
npm install -g node-inspector
Setting the log level to verbose will output a LOT of information. Based on the output you can find out where the errors/warnings are occurring and resolve them.
If git protocol is somehow involved and git's port is being blocked (TCP 9418), you could use https by doing
git config --global url.https://github.com/.insteadOf git://github.com/
npm install -g node-inspector
As you mentioned, you could use cnpm. Feel free to write your own answer and accept that one since that solved your problem.