npm deprecated command warnings appear when using outdated npm commands or flags. Common triggers include the deprecated --save flag (now default in npm 5+) and legacy commands like npm shrinkwrap.
This warning indicates you're using an npm command or flag that's been superseded by newer functionality. While the command may still work, it's considered legacy and may be removed in future npm versions. npm evolves over time, and commands that were once standard become deprecated as better alternatives emerge. The warning helps you migrate to modern practices.
Ensure you have modern npm:
npm install -g npm@latest
npm --version
# Should be v9+ or higherThe --save flag is no longer needed (default since npm 5):
# Old (deprecated)
npm install --save lodash
npm install -S lodash
# New (modern)
npm install lodashUpdate package.json scripts:
{
"scripts": {
"add-dep": "npm install lodash"
}
}npm-shrinkwrap.json is deprecated:
# Remove shrinkwrap
rm npm-shrinkwrap.json
# Regenerate modern lock file
npm installThe package-lock.json serves the same purpose with better tooling support.
Legacy install flags have been replaced:
# Old (deprecated)
npm install --global-style
npm install --legacy-bundling
# New
npm install --install-strategy=hoisted # Default
npm install --install-strategy=nested # Minimal deduplication
npm install --install-strategy=shallow # Flat structureFor reproducible builds, use npm ci:
# GitHub Actions
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run testnpm ci is faster and more reliable than npm install in CI environments.
If warnings come from dependencies:
# See which packages are deprecated
npm ls <deprecated-package>
# Update parent packages
npm update parent-package
# Or check for alternatives
npm auditCommon deprecated packages to replace:
- request → axios or node-fetch
- npmlog → custom logging
- rimraf v3 → rimraf v4+
Lifecycle script shortcuts still work:
- npm start = npm run start
- npm test = npm run test
But in CI/CD, prefer explicit commands: npm run test instead of npm test.
Package.json "engines" field can enforce npm version:
{
"engines": {
"npm": ">=9.0.0"
}
}Then in .npmrc: engine-strict=true
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
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 ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"