This error occurs when your system clock is set to a date before an SSL certificate's validity period begins, causing npm to reject the registry connection. Fixing your system time is the primary solution.
The CERT_NOT_YET_VALID error is an SSL certificate validation failure that happens when Node.js and npm verify the certificate from the npm registry (registry.npmjs.org). SSL certificates have a validity period with a start date and end date. When your system's date and time are set to a point before the certificate's start date, the certificate appears invalid to your machine, even though it's actually valid. This commonly occurs after rebooting systems without internet connectivity, across timezone changes without clock adjustment, or on devices like Raspberry Pi without battery-backed clocks.
Click the time/date display in the bottom-right corner of your taskbar. In the 'Date & time' settings window, ensure 'Set time automatically' toggle is enabled. This will sync your system to an internet time server.
For fastest results, restart your computer after enabling automatic time sync.
Ensure NTP (Network Time Protocol) is installed and running to keep your clock synchronized:
# Check current system time
date
# Install NTP if not present (Ubuntu/Debian)
sudo apt-get install ntp
# Restart NTP service
sudo service ntp restart
# For systems using systemd-timesyncd
sudo timedatectl status
sudo timedatectl set-ntp trueAfter updating, verify the time is correct with date command.
Older versions of Node.js and npm may have outdated or incomplete CA certificates. Upgrading ensures you have current certificate validation:
node --version
npm --version
npm install -g npm@latestFor Node.js, use nvm (Node Version Manager):
nvm install node
nvm use nodeOnce your clock is synchronized, retry your npm operation:
npm cache clean --force
npm install lodash --save-dev
npm installIf the error persists after confirming your system time is correct, the root cause may be elsewhere.
If you absolutely must proceed while troubleshooting the system clock, you can temporarily disable strict SSL validation. Warning: This reduces security:
export NODE_TLS_REJECT_UNAUTHORIZED=0
npm install
# Persistent (not recommended)
npm config set strict-ssl false
# Revert when done
npm config set strict-ssl true
unset NODE_TLS_REJECT_UNAUTHORIZEDAlways re-enable SSL verification and fix the underlying clock issue.
For corporate environments behind SSL inspection proxies: configure a custom CA certificate bundle using npm config set cafile '/path/to/ca-bundle.crt' or set NODE_EXTRA_CA_CERTS=/path/to/ca-bundle.crt. On containerized systems (Docker, Kubernetes), ensure time synchronization is properly inherited from the host system. Raspberry Pi users without hardware clock modules should run ntpd as a service to maintain time synchronization across reboots.
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