nodejs npm global config missing on windows
Asked Answered
S

8

76

I can't find at all where npm has its global settings stored.

npm config get userconfig

C:\Users\Jack\.npmrc

npm config get globalconfig

C:\Users\Jack\AppData\Roaming\npm\etc\npmrc

There's no files at either of these paths and yet

npm config get proxy -> returns my proxy url for work. which I want to delete.

npm config -g delete proxy

npm ERR! Error: ENOENT, unlink 'C:\Users\Jack\AppData\Roaming\npm\etc\npmrc'

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "config" "-g" "delete" "proxy"
npm ERR! cwd C:\f\Dropbox\apps
npm ERR! node -v v0.8.22
npm ERR! npm -v 1.2.14
npm ERR! path C:\Users\Jack\AppData\Roaming\npm\etc\npmrc
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\f\Dropbox\apps\npm-debug.log
npm ERR! not ok code 0
Sumba answered 20/3, 2013 at 23:41 Comment(1)
C
34

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.

Calcicole answered 3/4, 2014 at 19:29 Comment(4)
I never really did figure this out, It must be the Env variables mentioned but I swear I had unset them.Sumba
At the time I was using a script that set [environment]::SetEnvironmentVariable("http_proxy", $proxy, "User") unsetting "http_proxy", $null, "User" New console the proxy variable stuck. I concluded myself that windows doesn't really listen to user env settings changing. if you want to set one. Set it and keep it. If it's on/off like setting my proxy dependent on SSID I'm on, use the process env variable instead and put the check in the console profile. Sticking to $Env:http_prxy in the $profile.currentUserAllHosts file is what I went with.Sumba
it's unset <Environment Variable>, not unsetting. I'm not sure about the rest.Calcicole
"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." -- has helped me create the file quicklyNumerary
F
57

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

Florentinaflorentine answered 21/11, 2014 at 1:24 Comment(1)
just copied the original C:\Program Files\nodejs\node_modules\npm\npmrc to %APPDATA%\npm\node_modules\.npmrc and it works well. Many thanks!! The main config still placed to %USERPROFILE%\.npmrc, but didn't work without the manipulation aboveCentre
K
51

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
Koerlin answered 7/4, 2017 at 10:14 Comment(1)
There are multiple levels of where npm looks for the file. So the per-user config overrides the global and the local overrides the per-user. docs.npmjs.com/cli/v8/configuring-npm/npmrcFeral
C
34

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.

Calcicole answered 3/4, 2014 at 19:29 Comment(4)
I never really did figure this out, It must be the Env variables mentioned but I swear I had unset them.Sumba
At the time I was using a script that set [environment]::SetEnvironmentVariable("http_proxy", $proxy, "User") unsetting "http_proxy", $null, "User" New console the proxy variable stuck. I concluded myself that windows doesn't really listen to user env settings changing. if you want to set one. Set it and keep it. If it's on/off like setting my proxy dependent on SSID I'm on, use the process env variable instead and put the check in the console profile. Sticking to $Env:http_prxy in the $profile.currentUserAllHosts file is what I went with.Sumba
it's unset <Environment Variable>, not unsetting. I'm not sure about the rest.Calcicole
"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." -- has helped me create the file quicklyNumerary
B
18

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:

Bon answered 10/12, 2018 at 14:28 Comment(2)
This is extremely confusing! Should it be C:\Program Files\nodejs\node_modules\npm\npmrc (without a dot) -OR- C:\Program Files\nodejs\node_modules\npm\.npmrc (with a dot)? I have BOTH files. I tried it, and apparently both work. I recommend using the the file with a dot: .npmrc.Ampulla
But according to Microsoft AppData\Roaming is still per-user...?! How can i set the registry for all users on a given windows machine?Raeraeann
S
8

Have you tried running npm config list? And, if you want to see the defaults, run npm config ls -l.

Souse answered 23/2, 2016 at 13:32 Comment(1)
This is the answer I am looking for. After typing the above command, look for the following lines start with the keywords: globalconfig and userconfig, and they should list the files with the config values. I am running Node version 18.4.0, as the location might have updated compare to previous release.Nebiim
Y
5

On windows, used the below command that listed down all the default values for npm including the location of config file with variable name userconfig

npm config ls -l
Yogi answered 18/6, 2021 at 11:19 Comment(1)
And here is fastest solution to change/check npm config for current user: npm config editParaphrastic
I
4

Even though we have the .NPMRC can be in 3 locations, Please NOTE THAT - the file under the Per-User NPM config location take precedence over the Global & Built-in configurations.

  1. Global NPM config => C:\Users\%username%\AppData\Roaming\npm\etc\npmrc
  2. Per-user NPM config => C:\Users\%username%.npmrc
  3. Built-in NPM config => C:\Program Files\nodejs\node_modules\npm\npmrc

To find out which file is getting updated, try setting the proxy using the following command npm config set https-proxy https://username:[email protected]:6050

After that open the .npmrc files to see which file get updated.

Icebox answered 7/10, 2019 at 16:39 Comment(0)
R
3

Isn't this the path you are looking for?

C:\Program Files\nodejs\node_modules\npm\npmrc

I know that npm outputs that , but the global folder is the folder where node.js is installed and all the modules are.

Regimen answered 26/6, 2013 at 0:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.