The "certificate has expired" error occurs when npm encounters an SSL certificate that is past its validity date. This can happen with outdated system CA certificates, expired corporate certificates, or clock synchronization issues.
This error indicates that an SSL/TLS certificate in the chain has expired. Every SSL certificate has a validity period, typically 1-2 years. When npm connects to the registry, it validates the certificate chain, and if any certificate has passed its expiration date, the connection is rejected. This can occur at multiple levels: the registry's certificate (rare, as npmjs.com keeps theirs updated), an intermediate CA certificate, or a corporate proxy certificate that hasn't been renewed.
Incorrect system time can cause certificate validation failures:
# Check current date
date
# Sync time (Linux)
sudo ntpdate pool.ntp.org
# or
sudo timedatectl set-ntp true
# Windows
w32tm /resyncIdentify the expired certificate:
openssl s_client -connect registry.npmjs.org:443 2>/dev/null | openssl x509 -noout -datesThis shows notBefore and notAfter dates.
Refresh your system's certificate bundle:
# Ubuntu/Debian
sudo apt update && sudo apt install --reinstall ca-certificates
# CentOS/RHEL
sudo yum reinstall ca-certificates
# macOS
brew install ca-certificates
# or update via Software UpdateOlder Node.js versions may have outdated CA bundles:
# Check version
node --version
# Update via nvm
nvm install --lts
nvm use --lts
# Or update npm directly
npm install -g npm@latestRemove potentially cached bad certificates:
npm cache clean --force
rm -rf ~/.npm/_cacacheIf behind corporate proxy:
1. Ask IT for updated corporate CA certificate
2. Check if proxy certificate needs renewal
3. Update the cafile configuration:
npm config set cafile /path/to/new-corporate-ca.crtIn CI/CD environments, ensure build agents have updated CA certificates and synchronized time (especially for containers). Docker images should be rebuilt periodically to pick up CA updates. For air-gapped environments, manually update CA certificates. If using a time-sensitive HSM or TPM, ensure hardware clock is accurate.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error