错误:运行yarn命令时无法获取本地颁发者证书

Error: unable to get local issuer certificate while running yarn command

本文关键字:证书 获取 运行 yarn 命令 错误      更新时间:2023-09-26

我有自己的私有npm注册表http://something。我安装了yarn并尝试运行以下命令。

yarn

但是给出如下错误:

Trace: 
  Error: unable to get local issuer certificate
      at Error (native)
      at TLSSocket.<anonymous> (_tls_wrap.js:1017:38)
      at emitNone (events.js:67:13)
      at TLSSocket.emit (events.js:166:7)
      at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:582:8)
      at TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedone (_tls_wrap.js:424:38)

我发现了几个github问题和解决方案。

https://github.com/yarnpkg/yarn/issues/841https://github.com/yarnpkg/yarn/commit/b0611a6ee5220b0b1e955b271b6140640158f96c(在0.16.0中可用)

看起来我必须在纱线配置中将strict-ssl设置为false。我不知道该怎么做。我尝试在包装中以以下方式提供选项。

1)

{
config: {
"strict-ssl": false
}
}

2)

{
"strict-ssl": false
}

但我仍然得到相同的错误。我哪里做错了?

您可能因为在代理服务器后面运行而得到错误。要解决这个问题,打开Node.js命令提示符;输入并执行以下命令:

yarn config set "strict-ssl" false -g

意识到配置需要进入.yarnrc文件。我已经设置了下面的内容来让它工作。

cafile null
strict-ssl false

还请注意,yarn也从.npmrc文件中获取配置选项。

命令已更新。命令现在是:

yarn config set enableStrictSsl false

我的问题是一个损坏的节点安装。

卸载所有相关:node, npm, nvm, yarn;重新安装软件包解决了这个问题。