跳到主要内容
ecdsa.com
Yarn Classic (1.x); Yarn 4 prints the alias包管理器

错误信息

error Error: unable to get local issuer certificate

也可能输出为

  • YN0001: RequestError: unable to get local issuer certificate

Yarn 1.x 会打印“error Error: unable to get local issuer certificate”,后面跟着 Node.js 堆栈跟踪。如果注册表只发送叶子证书,文本则会变成“unable to verify the first certificate”。

含义

Yarn Classic 从注册表收到了证书链(叶子证书和中间证书),但 Node.js 不信任其上方的根证书。Yarn 会原样显示 Node.js 的错误。注册表通常没有问题;是这台机器缺少证书链所通向的公司根证书或代理根证书。

原因

修复方法

  1. 1.

    设置 Yarn 1 的 cafile

    让 Yarn 指向公司根证书(或者指向同时包含公共根证书的证书包,因为对注册表请求而言,cafile 会取代默认的根证书)。

    bash
    yarn config set cafile /etc/ssl/private-ca/corp-root-ca.pem
  2. 2.

    或者使用 NODE_EXTRA_CA_CERTS

    把根证书添加到 Node.js 的内置列表中,对 Yarn 以及其他任何设置了该变量的 Node.js 进程都生效。

    bash
    export NODE_EXTRA_CA_CERTS=/etc/ssl/private-ca/corp-root-ca.pem
    yarn install --frozen-lockfile
  3. 3.

    Yarn 4:httpsCaFilePath

    Yarn 4 报出的错误是“YN0001: RequestError: unable to get local issuer certificate”,CA 文件则从 .yarnrc.yml 中的 httpsCaFilePath 读取。

    yaml
    # Yarn 4: .yarnrc.yml
    httpsCaFilePath: /etc/ssl/private-ca/corp-root-ca.pem
  4. 4.

    检查锁文件使用了哪些主机

    如果 resolved 字段中的 URL 指向内部镜像,需要修复的是该镜像的证书或你的信任库,而不是注册表设置。

    bash
    # Which hosts does the lockfile download from?
    grep -oE 'resolved "https://[^/]+' yarn.lock | sort | uniq -c

相关错误

浏览完整的签名错误库