阅读.npmrc文件中的代理变量,但它不起作用。尽量避免手动下载所有需要的包并安装。
当前回答
在最后捆绑了不同的答案后,@Kayvar回答的前四行帮助我解决了这个问题:
npm config set registry http://registry.npmjs.org/
npm config set proxy http://myusername:mypassword@proxy.us.somecompany:8080
npm config set https-proxy http://myusername:mypassword@proxy.us.somecompany:8080
npm config set strict-ssl false
其他回答
在cmd或GIT Bash或其他提示符下使用以下命令
$ NPM配置代理http://192.168.1.101:4128
$ NPM配置http -proxy http://192.168.1.101:4128
其中192.168.1.101为代理IP, 4128为端口。根据您的代理设置进行更改。这对我很有用。
虽然已经有很多好的建议,但对于我的环境(Windows 7,使用PowerShell)和最后一个可用的node.js版本(v8.1.2),上述所有建议都不起作用,除非我遵循brunowego设置。
检查你的设置:
npm config list
代理背后的设置:
npm config set registry http://registry.npmjs.org/
npm config set http-proxy http://username:password@ip:port
npm config set https-proxy http://username:password@ip:port
npm config set proxy http://username:password@ip:port
npm set strict-ssl false
希望这能节省别人的时间
尝试在C:\Users\.npmrc中找到。npmrc
然后打开(记事本),写入并保存在里面:
proxy=http://<username>:<pass>@<proxyhost>:<port>
PS:请删除“<”和“>”!!
这对我很管用
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
npm set strict-ssl=false
在curl的页面上有关于SSL和证书问题的很好的信息。 我的大部分答案都是基于那里的信息。
使用strict-ssl false是不好的做法,可能会产生问题。我们可以做的是添加由“中间人”证书注入的证书。
如何在Windows上解决这个问题:
Download the CA Certificates from curl based on Mozilla's CA bundle. You can also use curl's "firefox-db2pem.sh" shellscript to convert your local Firefox database. Go to a webpage using https, for example Stackoverflow in Chrome or Internet Explorer Click the lock icon, click View certificates or "Valid" in Chrome Navigate to the Certification path. The top certificate, or the root certificate is the one we want to extract. Click that certificate and then "view certificate" Click the second tab, "Details". Click "Copy to file". Pick the DER format and make note of where you save the file. Pick a suitable filename, like rootcert.cer If you have Git installed you will have openssl.exe. Otherwise, install git for windows at this stage. Most likely the openssl executable will be at C:\Program Files\git\usr\bin\openssl.exe. We will use openssl to convert the file to the PEM format we need for NPM to understand it. Convert the file you saved in step 5 by using this command: openssl x509 -inform DES -in **rootcert**.cer -out outcert.pem -text where rootcert is the filename of the certificate you saved in step 5. Open the outcert.pem in a text-editor smart enough to understand line-endings, so not notepad. Find -----BEGIN CERTIFICATE----- lots of characters -----END CERTIFICATE----- and copy all text between them and also including the BEGIN / END lines Now we will paste that content to the end of the CA Cert bundle made in step 1. So open the cacert.pem in your advanced texteditor. Go to the end of the file and paste the content from previous step to the end of file. (Preserve the empty line below what you just pasted) Copy the saved cabundle.pem to a suitable place. Eg your %userprofile% or ~. Make note of the location of the file. Now we will tell npm/yarn to use the new bundle. In a commandline, write npm config set cafile **C:\Users\username\cacert.pem** where C:\Users\username\cacert.pem is the path from step 10. Optionally: turn on strict-ssl again, npm config set strict-ssl true
唷!我们成功了!现在npm可以理解如何连接了。额外的好处是,您可以告诉curl使用相同的cabundle。pem,它也能理解HTTPs。
推荐文章
- “node_modules”文件夹应该包含在git存储库中吗
- 使用package.json在全局和本地安装依赖项
- this.libOptions.parse不是一个函数
- 对嵌套文件夹运行npm install的最好方法是什么?
- 节点Multer异常字段
- 在Ubuntu上安装Bower
- 很好的初学者教程socket.io?
- CALL_AND_RETRY_LAST分配失败-进程内存不足
- 在Ubuntu上安装Node.js
- 使用express.js代理
- Node -使用NODE_MODULE_VERSION 51根据不同的Node.js版本编译
- RabbitMQ / AMQP:单队列,同一消息的多个消费者?
- Node.js同步执行系统命令
- 禁用包的postinstall脚本
- Node.js上的html解析器