nodejs npm global config missing on windows

2020-05-12 04:53发布

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

7条回答
我命由我不由天
2楼-- · 2020-05-12 05:37

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

This is covered here: https://github.com/npm/npm/wiki/Troubleshooting

查看更多
登录 后发表回答