This deprecation warning appeared briefly in npm 8.12.0 suggesting to use --location=global instead of -g. The deprecation was reversed in npm 8.12.1, but --location remains a valid modern alternative.
This warning indicated npm was transitioning from the traditional -g/--global flags to a new --location parameter. However, this deprecation was premature and was quickly reversed. In npm 8.12.0 (around Node.js 16.15.1), npm incorrectly deprecated --global. By npm 8.12.1, the deprecation was reverted—both syntaxes are valid. The --location parameter (introduced in npm 7) provides a unified way to specify configuration scope: global, user, or project. While not required, it's considered more explicit and modern.
The simplest fix is updating npm:
npm install -g npm@latest
npm --version
# Should be 8.12.1 or higherThe warning should no longer appear.
While -g still works, you can use the explicit syntax:
# Traditional (still valid)
npm install -g typescript
# Modern alternative
npm install typescript --location=globalBoth achieve the same result.
If you want to use the modern syntax in scripts:
Before:
npm install -g webpack-cli
npm config set registry https://registry.npmjs.org/ -gAfter:
npm install webpack-cli --location=global
npm config set registry https://registry.npmjs.org/ --location=globalThe --location flag accepts three values:
# Global (system-wide)
npm config set key value --location=global
# User (~/.npmrc)
npm config set key value --location=user
# Project (./npmrc in project)
npm config set key value --location=projectThe deprecation was a mistake in npm 8.12.0. The npm team intended to transition to --location but implemented it prematurely. They quickly reversed it in 8.12.1.
Both syntaxes are fully supported:
- -g / --global: Traditional, widely used
- --location=global: Modern, more explicit
For scripts and documentation, either is acceptable. The -g flag is shorter and more familiar to most developers.
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"