nodejs npm global config missing on windows
There is a problem with upgrading npm under Windows. The inital install done as part of the nodejs install using an msi package will create an npmrc file:
C:\Program Files\nodejs\node_modules\npm\npmrc
when you update npm using:
npm install -g npm@latest
it will install the new version in:
C:\Users\Jack\AppData\Roaming\npm
assuming that your name is Jack, which is %APPDATA%\npm.
The new install does not include an npmrc file and without it the global root directory will be based on where node was run from, hence it is C:\Program Files\nodejs\node_modules
You can check this by running:
npm root -g
This will not work as npm does not have permission to write into the "Program Files"
directory. You need to copy the npmrc file from the original install into the new install. By default the file only has the line below:
prefix=${APPDATA}\npm
For me (being on Windows 10) the npmrc file was located in:
%USERPROFILE%\.npmrc
Tested with:
- npm v4.2.0
- Node.js v7.8.0
It looks like the files npm
uses to edit its config files are not created on a clean install, as npm
has a default option for each one. This is why you can still get options with npm config get <option>
: having those files only overrides the defaults, it doesn't create the options from scratch.
I had never touched my npm config
stuff before today, even though I had had it for months now. None of the files were there yet, such as ~/.npmrc
(on a Windows 8.1 machine with Git Bash
), yet I could run npm config get <something>
and, if it was a correct npm
option, it returned a value. When I ran npm config set <option> <value>
, the file ~/.npmrc
seemed to be created automatically, with the option & its value as the only non-commented-out line.
As for deleting options, it looks like this just sets the value back to the default value, or does nothing if that option was never set or was unset & never reset. Additionally, if that option is the only explicitly set option, it looks like ~/.npmrc
is deleted, too, and recreated if you set
anything else later.
In your case (assuming it is still the same over a year later), it looks like you never set the proxy
option in npm
. Therefore, as npm
's config
help page says, it is set to whatever your http_proxy
(case-insensitive) environment variable is. This means there is nothing to delete
, unless you want to "delete" your HTTP proxy, although you could set
the option or environment variable to something else and hope neither breaks your set-up somehow.
How to figure it out
Start with npm root
-- it will show you the root folder for NPM packages for the current user.
Add -g
and you get a global folder. Don't forget to substract node_modules
.
Use npm config
/ npm config -g
and check that it'd create you a new .npmrc
/ npmrc
file for you.
Tested on Windows 10 Pro, NPM v.6.4.1:
Global NPM config
C:\Users\%username%\AppData\Roaming\npm\etc\npmrc
Per-user NPM config
C:\Users\%username%\.npmrc
Built-in NPM config
C:\Program Files\nodejs\node_modules\npm\npmrc
References:
- https://docs.npmjs.com/files/npmrc
- https://docs.npmjs.com/misc/config
- https://docs.npmjs.com/cli/root.html
Have you tried running npm config list
? And, if you want to see the defaults, run npm config ls -l
.