npm install hangs - node.js

This is my package.json:
{
"name": "my-example-app",
"version": "0.1.0",
"dependencies": {
"request": "*",
"nano": "3.3.x",
"async": "~0.2"
}
}
Now, when I open the cmd and run npm install, the install hangs. What am I doing wrong?

I had the same problem. The reason - wrong proxy was configured and because of that npm was unable to download packages.
So your best bet is to the see the output of
$ npm install --verbose
and identify the problem. If you have never configured proxy, then possible causes can be
Very outdated npm version.
Some problem with your internet connection.
Permissions are not sufficient for npm to modify files.

I was having the same problem. I tried a
npm config set registry http://registry.npmjs.org/
to turn off https. I also tried
npm set progress=false
to turn off the progress bar (it has been reported to slow down downloads).
The problem was with my network driver. I just needed to reboot and the lag went away.

You can try deleting package-lock.json and running npm install afterwards.
This worked for me.

I had the same issue on macOS, after some time struggling and searching around, this answer actually solved the issue for me:
npm config rm proxy
npm config rm https-proxy
npm config set registry http://registry.npmjs.org/

On MacOS, I was able to solve this by
networksetup -setv6off Wi-Fi
After installing, you can revert to the original configuration with
networksetup -setv6automatic Wi-Fi

Updating npm helped me on Mac OS. Use the command:
sudo npm install -g npm#latest

I am behind a corporate proxy, so I usually use an intermediate proxy to enable NTLM authentication.
I had hangs problem with npm install when using CNTLM proxy. With NTLM-APS (a similar proxy) the hangs were gone.

npm cache clear --force has fixed this issue for me in the past.
Furthermore, when running npm install on an air-gapped network (by the way, I provide a description about how to do this with Verdaccio), I had an issue where the install would hang at the very end. Turning off auditing (i.e. npm set audit false) on the machine on the air-gapped network resolved this issue.

While your mileage may vary, running npm cache verify fixed the issue for me.

It was strange but I guess I was just being impatient ran -> npm install --verbose and saw there was progress but it was just really slow!!! All I needed was patience :D

When your ssh key is password protected run ssh-add. npm probably hangs somewhere asking for your password.

Remove node_modules & package-lock.json from previous npm install and install again
rm -rf node_modules package-lock.json
npm install
or
If npm install loader is stuck and then pops up with..
npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY
npm ERR! errno UNABLE_TO_GET_ISSUER_CERT_LOCALLY
npm ERR! request to https://registry.npmjs.org/jest failed, reason: unable to get local issuer certificate"
then,
npm config set strict-ssl false
npm install
or
Follow to uninstall Node.js and install properly
https://www.geeksforgeeks.org/how-to-completely-remove-node-js-from-windows/
https://coding-boot-camp.github.io/full-stack/nodejs/how-to-install-nodejs
I personally had this issue and did all the steps I listed above. My issue was fixed with npm config set strict-ssl false

The registry(https://registry.npmjs.org/cordova) was blocked by our firewall. Unblocking it fixed the issue.

With due respect to all the answers, I switched to a different network and it worked for me.

Surprisingly just restarting my computer and running npm install again worked for me

Incase its useful to others, the following is what worked for me:
On my machine, although npm proxy was set correctly, npm install waits forever doing something like sill extract. Re-trying npm install waits forever on the same package again and again.
After waiting for a long timeout, npm install printed an error message implying that git was trying to fetch something.
The problem vanished after configuring git proxy using the below command:
git config --global http.proxy https://proxy-server:port
Note the https in the value of http.proxy without which the configuration did not take effect. Proxy server settings (http / https / port) might vary for users; hence its worth spending a bit of time experimenting with npm and git proxy server settings.

This method is working for me when npm blocks in installation Package for IONIC installation and ReactNative and another package npm.
You can change temporary:
npm config set prefix C:\Users\[username]\AppData\Roaming\npm\node_modules2
Change the path in environment variables. Set:
C:\Users[username]\AppData\Roaming\npm\node_modules2
Run the command to install your package.
Open file explorer, copy the link:
C:\Users[username]\AppData\Roaming\npm\node_modules
ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.
Copy your package file CMD to parent folder "npm".
Copy your package folder to parent folder "node_modules".
Now run:
npm config set prefix C:\Users\[username]\AppData\Roaming\npm
Change the path in environment variables. Set:
C:\Users[username]\AppData\Roaming\npm
Now the package is working correctly with the command line.

I'm not sure if your problem is being caused by the same reason that mine was, but I too was experiencing a hanging "npm install" and was able to fix it.
In my case, I wanted to install typescript locally in the project:
npm i typescript --save-dev
For some reason this was conflicting with a global install of typescript that I had, and the shell was just hanging forever instead of finishing or erroring...
I fixing it by first removing the globally installed typescript with the -g global flag:
npm uninstall typescript -g
After doing this the first command worked! 👍

I had npm hanging on installation of electronjs on Windows 10. I reinstalled and still it was hanging. But I noticed it got installed on another desktop in the same network. So finally I found the culprit. The issue was caused by Bitdefender free edition. There was no warning by the antivirus but it was blocking it silently. Even the console was not closing once the installation starts as it kept hanging. Disable antivirus/firewall if its on Windows and make sure network is open as npm does not seem to have a proper way of communicating network blocks and will keep proceeding indefinitely.

I've hit this problem a couple times.
When I was on VPN, I pressed Ctrl-C and disconnected from the VPN. Then npm install worked.
When I wasn't on VPN, I pressed Ctrl-C and connected to the VPN. Then, again, npm install worked.

For anyone on MacOS (I'm on Mojave 10.14), the following helped me out:
https://github.com/reactioncommerce/reaction/issues/1938#issuecomment-284207213
You'd run these commands
echo kern.maxfiles=65536 | sudo tee -a /etc/sysctl.conf
echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf
sudo sysctl -w kern.maxfiles=65536
sudo sysctl -w kern.maxfilesperproc=65536
ulimit -n 65536
Then try npm install once more.

check your environment variables for http and https
The existing entries might be creating some issues. Try deleting those entries.
Run "npm install" again.

I just turn off my windows firewall and it worked for me.
You can also try different versions of npm.

Check your .npmrc file for a registry entry (which identifies a server acting as a package cache.)
For me, npm install would hang partway through, and it was because of a old / non-responsive server listed in my .npmrc file. Remove the line or comment it out:
>cat ~/.npmrc
#registry=http://oldserver:4873
(And/or check with your IT / project lead as to why it's not working ;)

install nvm (Node Version Manager) and downgrade node version from 14 to 12 solved the issue in my case

Uninstalling and installing node and npm worked for me. I'm using Ubuntu 20.04.1 LTS

In my case npm install was hanging because it was waiting for me to input a password to my ssh key while cloning from git repository. There was no prompt and I realized this might be the case when I typed random character and nothing was echoed back. In my case I had to look at package.json file and clone locally repositories listed there. Then I updated package.json and changed paths of those git repositories to my local paths. After doing this everything else was installed without further errors.

On windows i suddenly had the same issue and tried all of the above, but the final solution for me was to switch off the ransomware protection which I had activated. It somehow doesn´t go well along with npm

I was having this error because I was running npm in a (docker) container in WSL2, and docker in WSL2 was configuring the wrong nameservers in the containers, making the container unable to resolve hosts.
To see if your container (or even your host) can resolve hosts, you can try running: curl https://github.com. In my case I received curl: (6) Could not resolve host: github.com.
The error in the docker container doesn't happen if I don't use the default bridge, instead I used a custom bridge and defined the container with it, in which case the resolv.conf file ends up with the correct nameserver:
$ cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0
The ip 127.0.0.11 corresponds to the docker DNS server, solving the problem in my case.
If you aren't running npm in a container, your issue may still be related to some misconfigured resolv.conf file (if you are in a Linux machine, or in Windows with WSL/WSL2).

In case anyone else encounters this, I left the npm install to run for long enough, and then the Jest extension crashed (v4.2.1), at which point the npm install completed successfully.
The Jest configuration seems to show that a test auto-watch feature was enabled. I haven't changed any Jest settings as far as I'm aware, so this must be out-of-the-box functionality.

Related

"npm install" hangs on sill: idealTree build

I've been trying to solve this over the last two days, or so, with no effect:
Solution that I have attempted include:
Deleting the package-lock.json file
Coordinating with the other dev on the project to align the Node.js
version and reinstalling the whole framework
Using --verbose as part of the "ndm i" command
Editing environmental variables to add NPM to them
Deleting the "node_modules" folder
Disabling, then re-enabling SSH
Trying with and without VPN being active
Clearing the cache via the command line, i.e. the node_modules step
above
This is a link to another topic on the same issue on SO that also seems to be outstanding: Link
I've reviewed the range of discussions on SO about the problem, to no particular avail, and I think I'm out of options. Any insight is appreciated
On MacOS (M1 chip) switching the IPV6 from Automatically to Link-local only fixed a very similar issue. When I tried adding registry.npmjs.org, npm was similarly getting "stuck".
To apply this setting go to System Preferences >> Network >> press Advanced >> TCP/IP tab >> on Configure IPv6 select Link-local only and apply
I found this solution in this thread
The issue was the connection to registry.npmjs.org, after the installation attempt finally processed.
The solution is that when you go to run "npm install", you have to add "registry.npmjs.org" at the end of it, and it sums up to:
npm i registry.npmjs.org
Make sure to run this from the folder of your NodeJS project.
Other useful links to consult:
NPM stuck on idealTree: timing idealTree
npm install hangs
stop "npm install" at [..................] | idealTree:regal: sill idealTree buildDeps
Error : getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443 --this one is for Angular, but still relevant.
As a final curiosity, going to registry.npmjs.org leads to this site:
where as https://www.npmjs.com/package/registry.npmjs.org leads to
You will note the command I used in this solution on the right side of that last screenshot.
Finally:
There is a typo in the error output: error refers to "registry.nPJMs.org", whereas the address has to be "registry.nPMJs.org".
I don't know if this should be brought to the attention of NodeJS devs, but there you go.
Add the following to node\node_modules\npm\.npmrc:
strict-ssl=false
See How to install NodeJS LTS on Windows as a local user (without admin rights) for details.
In my case, it was a weird internet connection problem. I tried to use a 4G sharing with my phone and tried to run npm install again, it worked. This way I was sure the problem was related to my connection set up and not node installation.
I unplugged my ethernet cable for 20s, plugged it in again and it worked, surprisingly.
On Ubuntu 22.10, disabling IPv6 fixed this for me.
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
To do this permanently, edit /etc/default/grub: change
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"
and then run
sudo update-grub
One more thing that might cause this is if you have incorrectly formatted certificates added to your npm config.
To check if this is a problem you can run
npm config get cert
npm config get key
To check if there is a value there, and if they look right.
If you're not sure, make a note of the values so you can restore if necessary and then remove them from the config
npm config delete cert
npm config delete key
Then try npm install again
To add the config back use
npm config set cert "<cert>"
npm config set key "<key>"
substituting you actual cert and key, (not the file, but the cert and key text)
more info on npm config here https://docs.npmjs.com/cli/v8/using-npm/config#cert

npm install freezes and shows idealTree:chatting: sill idealTree buildDeps

npm freezes when I am installing anything.
Even after deleting package-lock.json nothing changed.
Here is a similar question.
Can anyone tell how can I solve this problem??
It could be your having an issue with your certificates. Sometimes if you get this behavior there is an error in the certificate chain.
Try npm set strict-ssl false to see if this resolves your issue. Just remember if you do this you have disabled some of the security ssl gives you.
In my case being behind a VPN was causing this issue, I disconnected and it ran just fine
Updating my npm using npm install -g npm#latest solved the issue.
In my case, like #Damo said in their answer, it was a problem with TLS certificates (due to a corporate VPN). It was stuck at idealTree buildDeps for a long time, but eventually it finished with this error: SELF_SIGNED_CERT_IN_CHAIN.
I didn't want to run npm set strict-ssl false due to the security implications. The reason npm is getting an apparently invalid certificate is because I'm connected to the corporate VPN, which acts like a man-in-the-middle (but one that can be trusted, as opposed to most MITM situations, of course).
So the secure solution is to tell npm to trust my company's CA certificate.
This is done by npm config set cafile <path-to-cafile>.
Since I'm running an Ubuntu docker container, this is how I did it:
Obtained the company's CA certificate in PEM format. 1
Configured ubuntu to trust it following the steps of this answer
Verified that curl https://registry.npmjs.org/ is working without certificate errors
Tell npm to use the CA certificate: npm config set cafile /etc/ssl/certs/ca-certificates.crt (don't ask me why npm doesn't do this by default)
Done!
1 If you don't know who to ask for this, you can simply access any HTTPS website (such as stackoverflow) and see and download the root certificate (it won't be the standard stackoverflow certificate, because of your company's MITM VPN):
In my case it was a regresion in npm v7.x related to dependencies pointing to specific gitlab url:
"devDependencies": {
"npm-seven-issue-dep": "git+ssh://git#gitlab.com/klesun/npm-seven-issue-dep#5f1b313978986974d4364585e6bd3689276f1697"
}
Here is the bug report.
From what I observe, this freeze takes around 60 seconds (some network timeout perhaps) then installation finishes successfully.
I had the same issue. I figured out that my project was running in another terminal. So I closed that terminal and package was successfully installed, then I runned the project again.
Use it:
npm install passport --legacy-peer-deps
I tried all the solutions I found on the Internet: removing the proxy, setting the ssl cert to false, removing node_modules, removing the package-lock... nothing worked...
Then, I updated my WSL Ubuntu 20.04 to 22.04 and it worked!
sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo apt install update-manager-core
sudo nano /etc/update-manager/release-upgrades
change the Prompt value to Prompt = lts
sudo do-release-upgrade -d
cat /etc/os-release
for more info see this link

npm install Error: rollbackFailedOptional

When I try npm install new packages it shows me this error:
rollbackFailedOptional: verb npm-session 585aaecfe5f9a82
node --version
8.4.0
npm --version
5.3.0
# first this
> npm config rm proxy
> npm config rm https-proxy
# then this
> npm config set registry https://registry.npmjs.org/
solved my problem.
Again: Be sure to check whether you have internet connected properly.
Try this
npm config rm proxy
npm config rm https-proxy
In my case I had to edit the .npmrc directly and add the proxy settings manually.
proxy=http://yourorganizationproxy.com:8080
https-proxy=http://yourorganizationproxy.com:8080
Hope this helps someone.
The cause for this might be your current NPM registry. Try to check for a .npmrc file. These can be at various locations:
per-project config file (/path/to/my/project/.npmrc)
per-user config file (~/.npmrc)
global config file ($PREFIX/etc/npmrc)
npm builtin config file (/path/to/npm/npmrc)
Within these there can be something like
registry=https://mycustomregistry.example.org
which will take priority over the default one (http://registry.npmjs.org/). You can delete this line in the file or use the default registry like that:
npm <command> --registry http://registry.npmjs.org/
Most likely to be npm registry cannot be reached by npm. Check npm proxy configuration
I had exactly the same issue on Windows Server 2008 R2. I suspected Internet Explorer's Enhanced Security Configuration at first but after turning that off with no success the issue turned out to be that npm was not configured to use my corporate proxy connection to the internet.
It turns out that npm does not use the proxy settings in effect via Internet Options > Connections tab > LAN settings where the server is set to 'Automatically detect settings'. Being set to automatically detect settings does not guarantee that a proxy is indeed being used, it just means that Windows will automatically configure proxy settings for Internet Explorer if it finds a special'wpad.dat' file at http://wpad.[yourdomain.com]/wpad.dat.
You can test whether a wpad.dat file is in use in your organisation by typing the following into a web browser.
http://wpad.[yourcompany.domain]/wpad.dat
If no file is available then it is likely you are not using an organization-wide proxy. If one does get returned to the browser then...
Toward the bottom of this file, you should see a line saying
PROXY <host:port>;
It might be repeated if you have multiple proxies available. The host and port are needed in order to tell npm to use the proxy settings like so:
npm config set proxy http://[host]:[port]
and
npm config set https-proxy http://[host]:[port]
For example if your proxy is at my.proxy.com on port 8080 then the npm commands would be:
npm config set proxy http://my.proxy.com:8080
npm config set https-proxy http://my.proxy.com:8080
Once I had told npm which proxy to use all started working in I was able to run the install commands without a problem.
Thanks to the following post for help with the wpad file discovery.
In my case I had my npm set registry set to https://nexus, use:
npm config delete registry
This will revert to its default state.
I tried following options to fix this issue and it worked.
Uninstall Node.js version 8.
Install Node.js version 6.11.4
Use the registry option along with command to install any package.
For example to install express I used following command.
npm install express --registry http://registry.npmjs.org/
or
npm install express -g --registry http://registry.npmjs.org/
If you want to install locally in any specific folder then use below command. Below command will install express on path C:\Sample\Example1 .
C:\Sample1\Example1> npm install /Sample/Example1 express --registry http://registry.npmjs.org/
Note: If you are installing locally in a specific location then first go to that directory using command and then run above command. If you are not inside that directory and giving only path in command that will not work.
If you get package.json missing error then run below command before installing package locally
C:\Sample\Example1> npm init
above command will create package.json file. No need to provide any data. just hit enter.
Note: If you are behind a firewall then you may need to set a proxy.
Hi I'm also new to react and I also faced this problem after so many trouble I found solution: Just run in your command prompt or terminal :
npm config set registry http://registry.npmjs.org/
This will resolve your problem.
Reference link: http://blog.csdn.net/zhalcie2011/article/details/78726679
Make sure you can access the corporate repository you configured in npm is available.Check you VPN connection.
Else reset it back to default repository like below.
npm config set registry http://registry.npmjs.org/
Good Luck!!
The following commands resolved my issue:
npm config set proxy http://yourproxyurl.com:8080 (you need to enter your or your company proxy URL and 8080 should be replaced by your proxy port)
npm config set https-proxy http://yourproxyurl.com:8080
I had the same effect creating a react app with PhpStorm. And then at the end it just says done. Running the same command in the terminal gave me detailed errors. The project folder I've created was named react which seems to be a no-go.
Make sure your project folder is not named react.
If you have access to the registry but the error is still occurred nothing mentioned above wouldn't work. I noted that this problem is only applicable for local project's installation (i.e. if you use -g to global install everything is working fine).
What's resolved the problem for me: just remove an entry regarding a package you're going to install from a project's package.json file. After that next call to npm will work and install the package successfully.
Seem this bug is not fixed yet [1]. Some people get worked, some people not. I also get not worked.
I tried clear cache with command: npm cache verify then run install command again. I got worked.
[1]. https://github.com/npm/npm/issues/17246
I had the same issue. But it can run properly with switching from company's internal network to visitor network.
I set two system environment variables -
HTTP_PROXY = <_proxy_url_>
HTTPS_PROXY = <_proxy_url_>
This actually worked for me.
In some rarer occasions, check that the project can be built using regular npm commands. I ran into one that is configured to work with bower, so bower install <github_url> works while npm install <github_url> gives that unhelpful cryptic error message on all platforms...
While installing the Angular Command line tool (CLI), If you are getting Rollback Error then it may be occurring due to your network is connected with your Client Network or your Company Network where you are working on.
So Please try to install CLI in your public network (or Your Mobile's hotspot Network) then you would definitely get CLI installed.
Solution:
The default value of ‘proxy’ and ‘https-proxy’ key of npm config is NULL. After doing some more R & D then I tried to set the proxy setting value to above key (this solution works in my scenario).
Also, the same proxy settings need to be applied in IE browser Internet Settings >> Settings >> LAN settings.
Conclusion:
In corporate/some environment the proxy is a somewhat mandatory setting otherwise npm install will not work.
Issue on GitHub: https://github.com/SharePoint/sp-dev-docs/issues/3266
You can refer blog for detailed information
https://blogs2share.blogspot.com/2019/01/spfx-environment-setup-error.html
You can resolve the issue by looking if your network has any proxies, that is prohibiting the download process. My company's network had a firewall enabled, which was causing the issue for me. So I had to switch to an un-secure network (probably a hotspot from your mobile network), and that worked for me.
Mine was due to McAfee firewall.
It is set to Ask mode, so should have popped up a prompt to ask for internet connection, but it didn't!
Going into McAfee and (temporarily!) disabling the firewall allowed me to install.
I've already had the proxies set as described above and it was working until today. Then it turned out that now I need "http://" in front of my proxy address: "http://{proxyURL}:{proxyPort}". Then it finally worked.
Struggled with this issue for some time before figuring it out.
I'm using High Sierra (10.13.6)
Uninstalled and re-installed node and nvm multiple times - using the installer.pkg, HomeBrew, and then using the command line. IMO, the command line works the best.
I followed these steps:
1. Ran npm config ls -l
2. Checked that the value for globalconfig was $<installpath>/.nvm/versions/node/v12.16.3/etc/npmrc But when I tried to get to this path in the Terminal, it gave me No such file or directory
So I
3. created the folder etc, created the npmrc file and added this line in it.
registry = "https://registry.npmjs.org/"
I do not have the ~/.npmrc file in my $HOME
Then
4. I re-ran the npm install command.
Note that this still threw the rollbackFailedOptional: verb npm-session error, but this time it completed, though with a different error.
You could try these steps and see if it works.
For those who are curious, it threw a Response timeout while trying to fetch https://registry.npmjs.org/<package> (over 30000ms) error, so I added the timeout = "60000" to the /etc/npmrc file (as found on another Stackoverflow thread), and tried again. This worked for me.
Hope this helps!
Try this all command answered here to solve the problem https://stackoverflow.com/a/54173142/12142401
if problem persists
Do the following Steps
Completely Uninstall the nodejs checkout this answer for complete uninstallation of nodejs https://stackoverflow.com/a/20711410/12142401
Download the updated nodejs setup from their website
Install it in any drive but not on previously installed drive like if you installed in C drive then install in D,S,G Drive
Run your npm command it will completely work fine
If you use vpm as I do, try turn it off a sec, at least that's my problem
I had same problem.
I deleted files in my Mac
"/usr/local/bin/npm", "/usr/local/bin/node"
and deleted folder
"/usr/local/lib/node_modules"
and then installed the current latest feature version of node. then problem solved.
When downloaded LTS version, it shows the same problem.
So, try installing different versions of node and deleting old one.
Hi,
For people that use yarn package. Just go to the project folder that you are having this issue with. Let's say the project's folder name is chatApp:
cd chatApp
And then if you have already done yarn or yarn install then delete the node_modules folder and run the below command or if you haven't done yarn install, only run the blow command:
yarn cache clean
Once yarn has successfully cleaned the cache, run the below command:
yarn config set registry https://registry.npmjs.org/
That's it, this should fix the issue ✔️.
try this:
delete all file in folder: %APPDATA%\npm-cache\_locks
For Windows:
Run the installer again and choose to 'Repair' the installation
Worked for me
Try this. It worked fine for me
npm install /your_floder_location package_name --registry
http://registry.npmjs.org/
Below is the exact command for me for installing vue-router package in my laravel project (my project name vue_laravel)
aslam004:vue_laravel $ npm install
/var/www/html/projects/vue_laravel vue-router --registry http://registry.npmjs.org/
Good luck
use sudo before your command as
sudo npm install

npm ERR! Error: EPERM: operation not permitted, rename

When I execute npm install I get this error
npm ERR! Error: EPERM: operation not permitted, rename C:\projects******\node_modules\react-async-script' -> 'C:\projects*******\node_modules.react-async-script.DELETE'
I am running the cmd as administrator
I ran npm cache clean before
I made sure all the other applications don't have anything related to node_modules open
In my situation this helped:
Before proceeding to execute these commands close all VS Code instances.
clean cache with
npm cache clean --force
install the latest version of npm globally as admin:
npm install -g npm#latest --force
clean cache with
npm cache clean --force
Try to install your component once again.
I hope this fix your issue. If not, you may temporarily disable your antivirus program and try again.
For me i just closed the Code editor (VS Code) and then run the same command. And that solves the issue for me.
I got it working when tried npm install with a force option to fetch remote resources even if a local copy exists on disk. Try running
npm install --force
Updated
For some of my colleagues this solution was not working. But we tried using yarn instead of npm. It works (faster as well) without any issues all the time
yarn install [package-name]
Not package.json, but for whatever reason, my node_modules/ had become read-only. Resetting that fixed this.
If you want to avoid the --force option (which is always a better approach), I suggest making sure that you have stopped running the project, as this is usually the main reason for locking the files in almost 90% of the cases I have seen
I suggest the following steps in this order:
1- In Angular stopping ng s and in React stopping npm start usually solves this issue because usually this error happens if a development server is running the project as it locks some files & then npm can't update them thus throwing this error
2- If the above doesn't work, then try closing the code editor that has the workspace opened in it (maybe it was locking some files or something)
So try closing the code editor & running:
npm install
3- If still it doesn't work, then maybe you can try the --force option
npm install --force
I was getting that same error and according to https://github.com/Medium/phantomjs/issues/19 it could be caused by your antivirus software. I disabled mine for the duration of the install and executed "npm install" on cmd as admin and it worked.
Hope this helps.
I was getting the same thing. I didn't find this anywhere but it hit me that our VMs tend to change files to a read-only state. So I opened package.json's file properties and deselected Read-only in the "General" tab.
Steps
Go to the package.json file.
Right-click and select Properties.
In the General tab, Attributes section, deselect Read-only.
Click Apply to apply the change.
This is a typical error caused by Antivirus. There is a workaround for cases like mine, where I can't disable A/V (Company Policy).
You have to change the polyfills.js inside Npm package:
[NODE_HOME]/node_modules/npm/node_modules/graceful_fs/polyfills.js
Look for this statement:
if (process.platform === "win32") {
Inside of this statement, there is a timeout making a retry in case of error. The problem is that in some cases, after the timeout, the file is still locked by the A/V. The solution is rip out the timeout and let this statement in loop. The change with the previous code commented:
if (platform === "win32") {
fs.rename = (function (fs$rename) { return function (from, to, cb) {
var start = Date.now()
var backoff = 0;
fs$rename(from, to, function CB (er) {
if (er
&& (er.code === "EACCES" || er.code === "EPERM")
/*&& Date.now() - start < 60000*/) {
console.log("Retrying rename file: " + from + " <> " + to)
fs$rename(from, to, CB);
/*setTimeout(function() {
fs.stat(to, function (stater, st) {
if (stater && stater.code === "ENOENT")
fs$rename(from, to, CB);
else
cb(er)
})
}, backoff)*/
if (backoff < 100)
backoff += 10;
return;
}
if (cb) cb(er)
})
}})(fs.rename)
}
As Martin Kearn pointed out in a comment, closing Visual Studio resolved these npm permission issues for me. Evidently VS sometimes locks files in node_modules.
I have had this issue multiple times only in Windows
I try these in the order usually.
npm install --force
Check if node_modules is set to read-only and
remove if it is
Delete node_modules/
Check if any editor is opened
that could have access to the root folder of the project
Reboot :(
Usually trying npm install after one of those steps will resolve it.
Trying to rename a file to another filename that already exists can cause an EPERM error on Windows.
In my case, something got locked up and a quick reboot resolved it.
Closing PHPStorm fixed the issue for me.
just close the VS Code to solve the issue for me
I am using macOS catalina ,
npm init
I got error
operation not permitted, uv_cwd
in 2021, this is how you can fix this problem.
very simple:
step 1: go to parent folder
cd ../
step 2: go to your project folder again,
cd your-project-folder
That is it. It works.
I did the following:
Upgraded the npm to the latest version: npm install -g
npm#6.5.0-next.0
deleted the npm-cache folder from: c:/users/[username]/AppData/Roaming/npm-cache
Did cache clean : npm cache clean --force
Ran the npm install.
I struggeled with this too.
I finaly a solution that works fine if you use nvm:
cd ~/.nvm/versions/node/{your node version}/lib/
npm install npm
and that's it.
I'm using the terminal in VSCode and I realized I was using the bash terminal instead of the node terminal.
npm was failing for me at scandir for:
npm install -g webpack
...which might be caused by npm attempting to "modify" files that were potentially locked by other processes as mentioned here and in few other github threads. After force cleaning the cache, verifying cache, running as admin, disabling the AV, etc the solution that actually worked for me was closing any thing that might be placing a lock the files (i.e. restarting my computer).
I hope this helps someone struggling.
I had the same problem. The reason for the error is unsupported characters in the path to the file. Replaced the cyrillic in English - it helped.
For some, AppRoot\npm folder could be an issue. Sometimes the AppRoot folder is marked as network shared and thus Antivirus blocks the stuff. Follow below link for complete solution.
https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/
I hope this helps.
Open the command prompt as administrator and navigate to the project location and then run npm install. it worked for me.
I remounted my window disks with the metadata flag, and instantly helped: https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/
after that no need anymore to use sudo for npm commands as the metadata keeps windows and linux file/directory permissions in check.
In my case running npm: v6.9.0 && node: v10.16.1 on Windows, I had to run my CLI (git bash) as administrator. Then packages were installed without any warnings/errors
I had the same problem after updating to npm to 5.4.2, npm start giving the same error for most npm commands. Some solution suggest to run it with --no-optional, but it didn't always work.
Others suggested to downgrade, but I didn't want to downgrade.
I suspected that there was a problem with the installation, not sure what it was.
So I re-updated my npm:
npm i -g npm
and worked fine since then.
run the CLI as administrator always solve the problem for me
I came here with the same error, followed all the answers here, and none solved it. I started going through my package.json removing all suspicious packages. Removing this unnecessary one solved our problem. "npm": "^8.3.2"
I think it should be related to updating npm issue. As a workaround for now you can specify npm version as 8.3.1.
- name: Install latest npm version
run: npm install --global npm#8.3.1
I'm updating Angular 13 to 14 and I faced this issue.
None of these solutions worked so I just restarted the laptop and the npm i --force worked!
It seems like one process on the background is locking the access to certain node_modules files (you may have an ng serve running somewhere, or been launched by a git bash which you close but kept running on the background)
My answer is to do npm cache clean --force first. Then run npm install -g npm#5.3.0 to install npm 5.3.0 version. for me, this npm version works with no trouble.

npm gets stuck on fetchMetadata -> network

My npm is getting stuck a lot, whether its npm install from package.json or individual packages.
Right now, I'm not even able to sudo npm install node-inspector -g
I'm using node 6.2.1, npm 3.9.5 on ubuntu 16.04
npm cache clear didn't help.
The installation takes hours or fails.
Check if there any issues with proxies if you using any.
You can try also to set npm's endpoint manually:
npm config set registry="http://registry.npmjs.org"
try yarn installer instead of npm:
sudo npm install -g yarn
yarn install
I found it much more resilient to such problems.
You'll need to clear your https proxy settings:
npm config rm proxy
npm config rm https-proxy
I had this same problem, with several different installs hanging on fetchMetaData, including the install of yarn mentioned above. I am on a Mac and solved it by updating npm as follows:
npm install npm#latest -g
So if you are encountering this issue on Mac, then try updating and see if it solves your problem.
Did you configured a proxy? See if this returns something:
npm config get https-proxy
npm config get proxy
If you have values configured there, they might not match correct ones. If you shouldn't be using a proxy, you can delete them:
npm config delete https-proxy
npm config delete proxy
Docs: https://docs.npmjs.com/cli/config
For me it was double temp directories in Windows.
Open a command prompt and type:
echo %TEMP%
You should receive path to a single directory. If you receive multiple directories (I received C:\Users\\AppData\Local\Temp;C:\xampp\php) this might be the problem. You can fix it using this command:
SET TEMP="<correct path to temporary directory>"
where <correct path to temporary directory> might be the first path (before semicolon, that means C:\Users\<user>\AppData\Local\Temp in my case).
There are a lot of different things that can cause this issue.
I had tried a lot of things, including most of the answers posted here, but no luck.
For some weird reason, this was my ISP's issue. It worked fine when I tried on a different ISP.
I got the same issue. First of all try to run npm install with -verbose flag. That can help you identify your problem.
That command told me that I had some problem with tunneling socket:
tunneling socket could not be established, cause=write EPROTO 101057795:error:140770FC:SSL routines:SSL 23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794:
After that I googled the error and found thread on github about that problem. The problem was in proxy: previously I set up HTTP_PROXY environment variable and after removing then environment variable npm install completed without any error.
I had a similar issue to #giridhar but it wasn't related to the proxy, just that my ssh key wasn't setup properly.
When trying to do a git ls-remote from an ssh:// url. I was getting the prompt to enter my passphrase for my ssh key.
I had to run these commands on command line in order to stop getting asked for my pass phrase:
$ eval `ssh-agent -s`
$ ssh-add ~/.ssh/id_rsa
Once you enter your pass phrase, then you don't have to enter it again anymore.
I highly recommend reading this wiki from Atlassian if you need to setup an ssh key: https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html
For the major chunk of the people, the issue could be related to proxy settings and can be solved by the above-mentioned solutions.
For me, the issue was something else. I have private repository dependencies which are hosted at Bitbucket and are resolved through "git+ssh://git#bitbucket.org/" which intern uses SSH to retrieve the repo.
SSH by default prefers IPv6 if DNS retrieves AAAA record and if the host has one. Since Bitbucket does have AAAA record, SSH is done over IPv6. But my ISP doesn't support IPv6 (You could check if your ISP support's IPv6 by taking a test in http://ipv6-test.com/).
To solve this, you could force SSH client to use IPv4 instead of IPv6.
Set AddressFamily inet in /etc/ssh/ssh_config and restart SSH client.
On Ubuntu to restart SSH client use sudo service ssh restart
Having same problem. Fixed it by switching to correct version of node required by the project.
My project needed node >=v4.3 and <=v5.
1) Check node version being used by nvm ls
2) Use nvm use [version] or else install the specific version. if you don't have.

Resources