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 error code ENOENT npm error syscall spawn git npm error path git npm error errno -4058 npm error enoent An unknown git error occurred
How to fix "spawn git ENOENT" in npm
npm error code E401 npm error Incorrect or missing password.
How to fix 'E401 Unable to authenticate' errors with npm private registries
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm