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.
Fixes npm WARN deprecated npm WARN deprecated This command is deprecated. Use npm install instead
npm install -g npm@latest
npm --version
# Should be v9+ or highernpm install -g npm@latestnpm --version# Should be v9+ or highernpm WARN deprecated npm WARN deprecated This command is deprecated. Use npm install instead
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