node.js 错误!网络获取地址信息 ENOTFOUND
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23193614/
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
npm ERR! network getaddrinfo ENOTFOUND
提问by SharpCoder
I am getting npm ERR! network getaddrinfo ENOTFOUNDerror while trying to install any package using NPM. I know there are numerous threads on the same issue but I could not find any thread which can help me.
npm ERR! network getaddrinfo ENOTFOUND尝试使用 NPM 安装任何软件包时出现错误。我知道在同一问题上有很多线程,但我找不到任何可以帮助我的线程。
I have set the proxy & I think its something to do with proxy not being set correctly\not using the correct url.
我已经设置了代理,我认为这与没有正确设置代理有关\未使用正确的 url。
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
Is there any way to check the URL I am using while setting proxy is correct? Are there any steps I need to take in order rectify this issue?
在设置代理是否正确时,有什么方法可以检查我正在使用的 URL?我是否需要采取任何步骤来纠正此问题?


采纳答案by SharpCoder
I was setting proxy as
我将代理设置为
npm config set http_proxy=http://domain:8080
instead of using the correct way
而不是使用正确的方法
npm config set proxy http://domain:8080
回答by fibonacci
回答by Luqman_Ahmad
Instead of setting the proxy usingnpm config set http_proxy=http://address:8080go to ~/.npmrc and remove the proxy config. This resolved my issue.
而不是使用npm config set http_proxy=http://address:8080转到 ~/.npmrc 并删除代理配置来设置代理。这解决了我的问题。
回答by Ji?í Kovalsky
I also faced this error but I was not working behind a proxy server at the moment so using npm config set proxy=http://address:8080couldn't help and ~/.npmrcdidn't contain any proxy setting either. The solution in my case was just to restart my computer.
我也遇到了这个错误,但我目前没有在代理服务器后面工作,所以使用npm config set proxy=http://address:8080也无济于事,~/.npmrc也不包含任何代理设置。在我的情况下的解决方案只是重新启动我的计算机。
回答by Prakash
I got the exact same error and this is what i did.
我得到了完全相同的错误,这就是我所做的。
npm config get proxy
and it returned "null"
它返回“空”
Opened "C:\Users\Myname.npmrc" in a notepad and made some changes. This is how my .npmrc file looks now
在记事本中打开“C:\Users\Myname.npmrc”并进行一些更改。这就是我的 .npmrc 文件现在的样子
http-proxy=http://proxyhost/:proxyport
strict-ssl=false
registry=http://registry.npmjs.org/
回答by user2875912
does your proxy require you to authenticate? because if it does, you might want you configure your proxy like this.
您的代理是否要求您进行身份验证?因为如果是这样,您可能希望像这样配置代理。
placeholder names. usernameis a placeholder for your actual username. passwordis a placeholder for your actual password. proxy.company.comis a placeholder for your actualy proxy *port" is your actualy port the proxy goes through. its usualy 8080
占位符名称。 username是您实际用户名的占位符。 password是您实际密码的占位符。 proxy.company.com是您实际代理的占位符 *port" 是您代理经过的实际端口。通常是 8080
npm config set proxy "http://username:[email protected]:port"
npm config set https-proxy "http://username:[email protected]:port"
回答by Niladri
The solution which worked for me:
对我有用的解决方案:
- Delete proxy:
npm config delete proxy - Check
npm config get proxywhich should returnnull
- 删除代理:
npm config delete proxy - 检查
npm config get proxy哪个应该返回null
Now, check if you are able to install the package. If not working, try manually editing the config, type: npm config edit, remember you are in VI editor.
现在,检查您是否能够安装该软件包。如果不起作用,请尝试手动编辑配置,键入:npm config edit,记住您在 VI 编辑器中。
Add ;before(for commenting out):
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
添加;之前(注释掉):
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
Save and exit the file :x
保存并退出文件 :x
Now, try installing the packages. It should work.
现在,尝试安装软件包。它应该工作。
回答by eaglei22
for some reason my error kept pointing to the "proxy" property in the config file. Which was misleading. During my troubleshooting I was trying different values for the proxy and https-proxy properties, but would only get the error stating to make sure the proxy config was set properly, and pointing to an older value.
出于某种原因,我的错误一直指向配置文件中的“代理”属性。这是误导。在我的故障排除期间,我尝试了代理和 https-proxy 属性的不同值,但只会收到错误消息,说明确保代理配置设置正确,并指向旧值。
Using, NPM CONFIG LS -L command lists all the properties and values in the config file. I was then able to see the value in question was matching the https-proxy, therefore using the https-proxy. So I changed the proxy (my company uses different ones) and then it worked. figured I would add this, as with these subtle confusing errors, every perspective on it helps.
使用 NPM CONFIG LS -L 命令列出配置文件中的所有属性和值。然后我能够看到有问题的值与 https-proxy 匹配,因此使用了 https-proxy。所以我改变了代理(我的公司使用不同的代理)然后它就起作用了。我想我会添加这个,就像这些微妙的令人困惑的错误一样,每个角度都有帮助。
回答by sarnabtech
Just unset the proxy host using :
只需使用以下命令取消设置代理主机:
unset HOST
unset HOST
This worked for me.
这对我有用。
回答by simran agarwal
Make sure to use the latest npm version while installing packages using npm.
确保在使用 npm 安装软件包时使用最新的 npm 版本。
While installing JavaScript, mention the latest version of NodeJS. For example, while installing JavaScript using devtools, use the below code:
安装 JavaScript 时,请提及最新版本的 NodeJS。例如,在使用 devtools 安装 JavaScript 时,请使用以下代码:
devtools i --javascript nodejs:10.15.1
This will download and install the mentioned NodeJS version. Try installing the packages with npm after updating the version. This worked for me.
这将下载并安装提到的 NodeJS 版本。更新版本后尝试使用 npm 安装软件包。这对我有用。

