I\'ve been desperately trying to install modules using node.js but it always fails getting packages with npm.
I logged in as Administrator and used powershell/cmd wi
If you're in react native project, and Expo is running, then close it.
Re-install the package, and everything should be fine.
It turns out that you don’t have to run the command again as Administrator, and doing so won’t fix the problem.
Try:
npm cache clean
first.
If that doesn’t fix things, take a look in %APPDATA%\npm-cache
, or if you’re using PowerShell, $env:APPDATA\npm-cache
.
After cleaning the cache, you may still be left with remnants. Manually remove everything in that directory, and try again. This has always fixed things for me.
As @Crazzymatt was mentioning, as of the npm@5 version and up, we need to use npm cache verify
instead of npm cache clean
. Or else you will get an error as preceding.
npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.
(Source: MSDN Blog post)
This is the flow often happens in this case. You run a command with no admin rights, you get message npm ERR! Please try running this command again as root/Administrator.
. Then you open one more CLI(cmd, powershell, bash or whatever) and don't close the previous CLI. It appears you have 2 prompts opened in the same directory. And until you close CLI which runs with no admin rights you will be continuously getting npm ERR! Please try running this command again as root/Administrator.
So close CLI which runs with no admins rights before running a new one.
NOTE: a lot of IDE has embedded CLI(Visual Studio, VS Code etc) so please close the instance of IDE as well
Here is how I fixed this on my Windows (7) Dev. environment. I assume the following...
Okay, let's get to it:
Update any packages where a version check is returning a warning ("npm WARN"..) for example...
npm update -g npm
npm update -g graceful-fs
Next we want to force a cache clean. This is flagged by an '--f' or '-f'..
npm cache clean --f
In Widows Explorer search for the following path
%APPDATA%\npm-cache
And Delete it's contents
Hope this helps someone!!
I had the same problem, what I did to solve it was ran the cmd.exe as administrator even though my account was already set as an administrator.
That should fix the issue hopefully