Windows 上缺少 nodejs npm 全局配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15536872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nodejs npm global config missing on windows
提问by Hyman
I can't find at all where npm has its global settings stored.
我根本找不到 npm 存储其全局设置的位置。
npm config get userconfig
npm 配置获取用户配置
C:\Users\Hyman\.npmrc
npm config get globalconfig
npm 配置获取全局配置
C:\Users\Hyman\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 get proxy -> 返回我的代理 url 以进行工作。我想删除。
npm config -g delete proxy
npm config -g 删除代理
npm ERR! Error: ENOENT, unlink 'C:\Users\Hyman\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\Hyman\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
采纳答案by trysis
It looks like the files npmuses to edit its config files are not created on a clean install, as npmhas 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.
看起来npm用于编辑其配置文件的文件不是在全新安装时创建的,因为npm每个文件都有一个默认选项。这就是为什么您仍然可以获得选项的原因npm config get <option>:让这些文件只覆盖默认值,它不会从头开始创建选项。
I had never touched my npm configstuff 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 npmoption, it returned a value. When I ran npm config set <option> <value>, the file ~/.npmrcseemed to be created automatically, with the option & its value as the only non-commented-out line.
npm config在今天之前我从来没有碰过我的东西,即使我已经拥有它几个月了。还没有任何文件存在,例如~/.npmrc(在带有 的 Windows 8.1 机器上Git Bash),但我可以运行npm config get <something>,如果它是一个正确的npm选项,它会返回一个值。当我运行时npm config set <option> <value>,文件~/.npmrc似乎是自动创建的,选项及其值是唯一未注释掉的行。
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 ~/.npmrcis deleted, too, and recreated if you setanything else later.
至于删除选项,看起来这只是将值设置回默认值,或者如果该选项从未设置或未设置且从未重置,则不执行任何操作。此外,如果该选项是唯一明确设置的选项,它看起来也~/.npmrc被删除了,如果您set以后有其他任何事情,则会重新创建。
In your case (assuming it is still the same over a year later), it looks like you never set the proxyoption in npm. Therefore, as npm's confighelp 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 setthe option or environment variable to something else and hope neither breaks your set-up somehow.
在您的情况下(假设它在一年后仍然相同),看起来您从未proxy在npm. 因此,作为npm的config帮助页说,它被设置为任何你http_proxy(不区分大小写)环境变量。这意味着没有什么可以delete,除非您想“删除”您的 HTTP 代理,尽管您可以set将选项或环境变量设置为其他内容,并希望不会以某种方式破坏您的设置。
回答by oenpelli
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:
windows下升级npm有问题。使用 msi 包作为 nodejs 安装的一部分完成的初始安装将创建一个 npmrc 文件:
C:\Program Files\nodejs\node_modules\npm\npmrc
C:\Program Files\nodejs\node_modules\npm\npmrc
when you update npm using:
当您使用以下命令更新 npm 时:
npm install -g npm@latest
npm install -g npm@latest
it will install the new version in:
它将在以下位置安装新版本:
C:\Users\Hyman\AppData\Roaming\npm
C:\Users\Hyman\AppData\Roaming\npm
assuming that your name is Hyman, which is %APPDATA%\npm.
假设你的名字是 Hyman,也就是 %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
新安装不包含 npmrc 文件,如果没有它,全局根目录将基于运行节点的位置,因此它是 C:\Program Files\nodejs\node_modules
You can check this by running:
您可以通过运行来检查:
npm root -g
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:
这将不起作用,因为 npm 没有写入"Program Files"目录的权限。您需要将原始安装中的 npmrc 文件复制到新安装中。默认情况下,该文件只有以下行:
prefix=${APPDATA}\npm
prefix=${APPDATA}\npm
This is covered here: https://github.com/npm/npm/wiki/Troubleshooting
回答by Benny Neugebauer
For me (being on Windows 10) the npmrc filewas located in:
对我来说(在 Windows 10 上)npmrc 文件位于:
%USERPROFILE%\.npmrc
Tested with:
测试:
- npm v4.2.0
- Node.js v7.8.0
- npm v4.2.0
- Node.js v7.8.0
回答by user1990218
Have you tried running npm config list? And, if you want to see the defaults, run npm config ls -l.
你试过跑步npm config list吗?而且,如果您想查看默认值,请运行npm config ls -l.
回答by Vladimir Salin
How to figure it out
如何弄清楚
Start with npm root-- it will show you the root folder for NPM packages for the current user.
Add -gand you get a global folder. Don't forget to substract node_modules.
从npm root-开始,它将显示当前用户的 NPM 包的根文件夹。添加-g,您将获得一个全局文件夹。不要忘记减去node_modules.
Use npm config/ npm config -gand check that it'd create you a new .npmrc/ npmrcfile for you.
使用npm config/npm config -g并检查它是否会为您创建一个新的.npmrc/npmrc文件。
Tested on Windows 10 Pro, NPM v.6.4.1:
在 Windows 10 Pro、NPM v.6.4.1 上测试:
Global NPM config
全局 NPM 配置
C:\Users\%username%\AppData\Roaming\npm\etc\npmrc
Per-user NPM config
每用户 NPM 配置
C:\Users\%username%\.npmrc
Built-in NPM config
内置 NPM 配置
C:\Program Files\nodejs\node_modules\npm\npmrc
References:
参考:
回答by Avner Solomon
Isn't this the path you are looking for?
这不是你要找的路吗?
C:\Program Files\nodejs\node_modules\npm\npmmrc
C:\Program Files\nodejs\node_modules\npm\npmmrc
I know that npm outputs that , but the global folder is the folder where node.js is installed and all the modules are.
我知道 npm 输出那个,但是全局文件夹是安装 node.js 和所有模块的文件夹。
回答by Cleancoder
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.
即使我们有 .NPMRC 可以在 3 个位置,请注意 - Per-User NPM 配置位置下的文件优先于全局和内置配置。
- 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
- 全局 NPM 配置 => C:\Users\%username%\AppData\Roaming\npm\etc\npmrc
- 每用户 NPM 配置 => C:\Users\%username%.npmrc
- 内置 NPM 配置 => 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
要找出哪个文件正在更新,请尝试使用以下命令设置代理 npm config set https-proxy https://username:[email protected]:6050
After that open the .npmrc files to see which file get updated.
之后打开 .npmrc 文件以查看哪个文件得到更新。

