安装grunt时NodeJS NPM代理错误
当我试图通过npm
安装grunt
,出现以下错误:
C:\Program Files\nodejs\node_modules\npm>npm install -g grunt npm ERR! network connect ETIMEDOUT npm ERR! network This is most likely not a problem with npm itself npm ERR! network and is related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config' npm ERR! System Windows_NT 6.1.7601 npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "grunt" npm ERR! cwd C:\Program Files\nodejs\node_modules\npm npm ERR! node -v v0.10.33 npm ERR! npm -v 1.4.28 npm ERR! syscall connect npm ERR! code ETIMEDOUT npm ERR! errno ETIMEDOUT npm ERR! npm ERR! Additional logging details can be found in: npm ERR! C:\Program Files\nodejs\node_modules\npm\npm-debug.log npm ERR! not ok code 0
我正在使用企业代理configuration,我相信我有这个错误,因为它的configuration。 为了成功安装grunt,我需要更改哪些内容?
你需要configurationnpmconfiguration文件,这可以在terminal完成:
npm config set proxy http://proxy.company.com:8080 npm config set https-proxy http://proxy.company.com:8080
你的错误日志build议看到'npm help config',所以我认为问题来自那里。
如果你想要更多的解释链接看到这个博客条目 (还有很多)
祝你好运!
如果您在“windows”域中使用代理,请将域名添加到代理url中:
npm config set proxy http://domain%5Cuser:password@proxy.company.com:8080 npm config set https-proxy http://domain%5Cuser:password@proxy.company.com:8080
您需要将反斜杠编码为http uristring:%5C
如果您的用户名或密码中有特殊字符,则还需要对这些字符进行编码。 请记住,这些关键信息以纯文本forms存储在npmconfiguration文件(%HOME%\。npmrc)中。 也可能需要将npmregistry指向http源:
npm config set registry "http://registry.npmjs.org" npm config set strict-ssl false
这个configuration适合我。 你需要检查你的http和https端口(通常分别是80和443),但在我的情况下,我正在使用端口80。
npm config set proxy http://user:password@proxy.url.com:80 npm config set https-proxy http://user:password@proxy.url.com:80
您可以通过get
命令检查您的代理设置
npm config get proxy npm config get https-proxy
我之前也有同样的问题,因为我这样打错了代理configuration:
npm config set proxy http://localhost:8080/ npm config set https-proxy http://localhost:8080/ npm config set strict-ssl false
这使npm客户端尝试打localhost:8080来拉模块,而不是正确的互联网端点。
所以经过几天的沮丧,我访问了这个链接
https://docs.npmjs.com/cli/config
然后运行
npm config edit
其中打开文件里面的文件,我删除了我上面添加的这三行,然后一切工作正常。
请使用npm config set proxy http://xx.aa.bb.cc:port对我来说非常感谢!
下面的选项使它适用于我:
npmconfiguration设置registry“ http://registry.npmjs.org ”
npm config set proxy http:// user:password@proxy.url.com:proxy-port
npm config set strict-ssl false
npm install -g -d哟
如果你感到沮丧,并且这个猴子生意都没有为你工作,只需下载并运行最新的MSI。 https://nodejs.org/en/download/
你可以运行这个cmd
npm config set <key> <value> [-g|--global] npm config get <key> npm config delete <key> npm config list npm config edit npm get <key> npm set <key> <value> [-g|--global]
npmrc.txt会运行你可以改变你的链接和端口
proxy =http://proxy.company.com:8080 https-proxy = http://proxy.company.com:8080
参考