Skip to content
ecdsa.com
npm (Node.js)Package managers

Error message

npm error code ERR_TLS_CERT_ALTNAME_INVALID

Also printed as

  • npm ERR! code ERR_TLS_CERT_ALTNAME_INVALID
  • npm error request to https://registry.example.com/lodash failed, reason: Hostname/IP does not match certificate's altnames: Host: registry.example.com. is not in the cert's altnames: DNS:www.example.com

npm 10 and later print "npm error code ERR_TLS_CERT_ALTNAME_INVALID", npm 9 and older "npm ERR! code ERR_TLS_CERT_ALTNAME_INVALID". The host and altnames in the reason line come from your configuration and the server's certificate.

npm (Node.js) — registry request over HTTPS

What it means

The registry's certificate is trusted, but it was not issued for the host name in the registry URL npm used. The reason line spells out both sides: the host npm asked for and the names the certificate carries. Typical after a registry moves to a new name, or when the registry URL uses an alias, an IP address or the wrong environment.

Why it happens

How to fix it

  1. 1.

    Compare npm's registry setting with the certificate

    Print the configured registry (and proxy settings) and the certificate's SAN list. Lockfiles also contain resolved URLs; they must use the same host.

    bash
    npm config get registry
    npm config list | grep -iE 'registry|proxy'
    echo | openssl s_client -connect registry.example.com:443 -servername registry.example.com 2>/dev/null \
      | openssl x509 -noout -ext subjectAltName
  2. 2.

    Point npm at the certificate's name

    Update the registry setting in every .npmrc level (and regenerate lockfiles if they contain the old host).

    bash
    # Use the host name the registry's certificate was issued for
    npm config set registry https://npm.example.com/
  3. 3.

    Registry owners: cover every name in use

    Reissue the registry's certificate with all host names clients use, including aliases kept for compatibility.

    bash
    # Registry owners: include every name clients use
    sudo certbot certonly --nginx -d npm.example.com -d registry.example.com

Related errors

Browse the full signature error database