node.js 没有 ssl 的 npm 安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8874363/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:01:19  来源:igfitidea点击:

npm install without ssl

node.jssslnpm

提问by Ken Hirakawa

I have an Ubuntu VM that is having trouble connecting to sites with ssl, i.e. https. It can successfully download artifacts from the internet if the url begins with http.

我有一个 Ubuntu 虚拟机,它在使用 ssl(即 https)连接到站点时遇到问题。如果 url 以 http 开头,它可以成功地从 Internet 下载工件。

npm install will download dependencies via https. Is there anyway make it download via http?

npm install 将通过 https 下载依赖项。无论如何让它通过http下载吗?

回答by colinf

Try changing the registry to the http version rather that the default https one using the command

尝试使用命令将注册表更改为 http 版本而不是默认的 https 版本

npm config set registry http://registry.npmjs.org/

回答by Creasixtine

As conlinf said, the following should work :

正如 conlinf 所说,以下应该有效:

npm config set registry http://registry.npmjs.org/

npm config set registry http://registry.npmjs.org/

Now, to add my word, you should also consider that downloading without ssl allows a man-in-the-middle attack. It is only to add a warning to people who would read the post.

现在,补充一下,您还应该考虑在没有 ssl 的情况下进行下载会导致中间人攻击。它只是向阅读该帖子的人添加警告。

If you are a solo developer there should be not much trouble downloading in httpdirectly, but if I wanted to attack a company using node.js I would consider delivering malicious code through npm... And performing such an attack without ssl will be much easier.

如果你是一个单独的开发者,http直接下载应该不会有太大的问题,但是如果我想使用 node.js 攻击一家公司,我会考虑通过 npm 传递恶意代码......并且在没有 ssl 的情况下执行这样的攻击会容易得多.

回答by phyatt

After much trial and error I found that in addition to all that was said above, I also need to set the https-proxyto the value of the http proxy.

经过多次反复试验,我发现除了上面所说的之外,我还需要将 设置https-proxy为 http 的值proxy

So the end .npmrc file looks like

所以最后的 .npmrc 文件看起来像

proxy=http://username:[email protected]:port/
https-proxy=http://username:[email protected]:port/
strict-ssl=false
registry=http://registry.npmjs.org/

Note that proxy and https-proxy are identical!

请注意,proxy 和 https-proxy 是相同的!

See the comments on this thread for more info:

有关更多信息,请参阅此线程的评论:

https://github.com/npm/npm/issues/8034

https://github.com/npm/npm/issues/8034

Also I ran a npm cache clean --forceafter updating the npmrc for good measure but I am not sure if it is required.

此外,我npm cache clean --force在更新 npmrc 后运行了一个很好的措施,但我不确定是否需要它。

Hope that helps.

希望有帮助。

回答by Jeremy Fiel

changing ssl-strict worked for me behind a corporate firewall

在公司防火墙后面更改 ssl-strict 对我有用

npm config set ssl-strict=false

npm config set ssl-strict=false