By default, NPM stores the user config in ~/.npmrc
. I had a load of stuff in my user config which I didn't want to interfere with for my main project, but I was switching to a second project which required different configuration, so I just did:
npm config set userconfig C:\path\to\another\directory\.npmrc
.
To my surprise, NPM added a new entry userconfig
into my existing user config at ~/.npmrc
. This doesn't make sense to me - seems NPM needs to know where the user config is in order to find out where it is!
Now NPM ignores any properties I put into my new NPMRC file and only takes properties from ~/.npmrc
. Even more strangely, npm config list
contains a userconfig header (semicolon-prefixed line) specifying my new location, but the contents come from ~/.npmrc
.
For example, if I set my email as "[email protected]" in the ~/.npmrc
and as "[email protected]" in my new NPMRC, npm config list
reports something like this:
; cli configs
user-agent = "npm/3.10.8 node/v6.9.1 win32 x64"
; userconfig C:\path\to\another\directory\.npmrc
(... other properties ...)
email = "[email protected]"
(... other properties ...)
userconfig = "C:\path\to\another\directory\.npmrc"
; builtin config undefined
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\
; HOME = C:\Users\MyUsername
; "npm config ls -l" to show all defaults.
The value has come from ~/.npmrc
despite appearances (I double-checked the value in the new NPMRC is definitely "[email protected]").
I thought this might be a bug in NPM so I upgraded my Node/NPM to the latest version, but it still behaves the same way. Am I using userconfig
wrong and how should it work?
npmrc Files Per-project config file: /path/to/my/project/. npmrc. Per-user config file: ~/. npmrc.
npm config edit Opens the config file in an editor. Use the --global flag to edit the global config. now you can delete what ever the registry's you don't want and save file. npm config list will display the list of available now.
npmrc file you are using is at, but you don't need to. For any project you have, stick a . npmrc file in the root directory, right next to ${rootDir}/node_modules/ and ${rootDir}/package. json .
From https://docs.npmjs.com/misc/config
npmrc Files
The four relevant files are:
- per-project configuration file (/path/to/my/project/.npmrc)
- per-user configuration file (defaults to $HOME/.npmrc; configurable via CLI option --userconfig or environment variable $NPM_CONFIG_USERCONFIG)
- global configuration file (defaults to $PREFIX/etc/npmrc; configurable via CLI option --globalconfig or environment variable $NPM_CONFIG_GLOBALCONFIG)
- npm's built-in configuration file (/path/to/npm/npmrc)
Call a command like npm --userconfig /another/path/to/npmrc install
and it will use that instead of the ~/.npmrc file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With