阅读.npmrc文件中的代理变量,但它不起作用。尽量避免手动下载所有需要的包并安装。
当前回答
$ npm config set proxy http://login:pass@host:port
$ npm config set https-proxy http://login:pass@host:port
其他回答
去环境变量和删除或设置为空
HTTP_PROXY和HTTPS_PROXY
这也将解决企业环境的代理问题
要设置http代理,请设置-g标志:
Sudo NPM配置代理http://proxy_host:port -g
对于https代理,再次确保设置了-g标志:
Sudo NPM配置http -proxy http://proxy_host:port -g
虽然我在配置中设置了代理,但问题并没有解决 这个对我很有用:
npm——http -proxy http://XX.AA.AA.BB:8080安装cordova插件 npm——代理http://XX.AA.AA.BB:8080安装
当我在代理设置中没有http/http前缀时,即使代理主机和端口是正确的值,npm也会失败。只有在添加协议前缀后,它才能正常工作。
在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。
推荐文章
- DeprecationWarning:当我将脚本移动到另一个服务器时,由于安全性和可用性问题,Buffer()已弃用
- 我如何确定正确的“max-old-space-size”为Node.js?
- npm犯错!代码UNABLE_TO_GET_ISSUER_CERT_LOCALLY
- Access-Control-Allow-Origin不允许Origin < Origin >
- 如何获得所有已注册的快捷路线?
- 你可以为你的组织托管一个私有的存储库来使用npm吗?
- 如何定位父文件夹?
- Gulp命令未找到-安装Gulp后错误
- 在Node.js中写入文件时创建目录
- 如何将自定义脚本添加到包中。Json文件,运行javascript文件?
- 使用child_process。execSync但保持输出在控制台
- SyntaxError:在严格模式下使用const
- 在Node.js中递归复制文件夹
- 如何在node.js中设置默认时区?
- “react-scripts”不被视为内部或外部命令