在我的公司,有一个自动签名的 ssl 证书。所以它们是一些因为它而无法安装的 npm 包。
我已经在
strict-ssl=false
或 .npmrc
命令参数中添加了 --strict-ssl=false
。
它适用于某些软件包,但有些软件包似乎不负责此选项。
例如,我尝试安装Cypress:
命令:
npm i cypress --save-dev --strict-ssl=false
错误日志:
> [email protected] postinstall /Users/mchoraine/Documents/Workplace/SAMSE/rechercheproduit/rechercheproduit-front/node_modules/cypress
> node index.js --exec install
Installing Cypress (version: 3.4.0)
✖ Downloading Cypress
→ Cypress Version: 3.4.0
Unzipping Cypress
Finishing Installation
The Cypress App could not be downloaded.
Please check network connectivity and try again:
----------
URL: https://download.cypress.io/desktop/3.4.0?platform=darwin&arch=x64
Error: self signed certificate in certificate chain
----------
Platform: darwin (18.6.0)
Cypress Version: 3.4.0
问题似乎仅发生在带有
postinstall
的软件包上
最明智的做法是更改 SSL 证书,但不幸的是这是不可能的。
那么您是否知道绕过 npm postinstall 上的证书验证的替代方法?
预先感谢您的建议。
获取公司证书的副本,然后在运行 npm 命令之前将 NODE_EXTRA_CA_CERTS 环境变量设置为指向它:
export NODE_EXTRA_CA_CERTS=path/to/certificate.crt
安装后脚本是一个单独的节点程序,因此 npm 标志不会影响它。
感谢“zerdos”,他在相关的 GitHub 问题上发布了此解决方案:https://github.com/cypress-io/cypress/issues/1401#issuecomment-393591520
对我来说以下解决方案有效。
操作系统 - Windows 10
终端 - git bash
在安装 cypress 之前运行这些命令。
setx HTTP_PROXY <your company proxy url>
setx NODE_EXTRA_CA_CERTS <path to cerm.pem file>
这些将被设置为系统中的环境变量以供将来使用。 如果您不需要它们,您可以随时摆脱它们。
Windows 11.=>
我从 cypress cdn 下载了二进制文件到我的下载文件夹并在终端中运行它
$env:CYPRESS_INSTALL_BINARY="C:\Users\YourName\Downloads\cypress.zip"
npm install cypress