[BUG] `npm.cmd` uses deprecated switch `-g`
Problem
Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] I am using the latest npm Current Behavior When invoking `npm --version` on Windows there is a warning about a deprecated commandline switch: [code block] Expected Behavior No warning when no deprecated switch is used. Steps To Reproduce After upgrading npm to version 8.12.0 with npm-windows-upgrade `npm` always shows a warning on every execution about the deprecated switch `-g`. Environment - npm: 8.12.0 - Node.js: 16.15.0 - OS Name: Windows 11
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Remove Deprecated Switch Usage in npm Command
The warning about the deprecated switch '-g' occurs because the command is being invoked with an outdated or incorrect syntax that includes the deprecated flag. This typically happens when scripts or configurations still reference the old flag, which is no longer supported in the latest npm versions.
Awaiting Verification
Be the first to verify this fix
- 1
Check npm Configuration
Inspect the npm configuration to identify if the deprecated '-g' switch is being set in any npm scripts or global configurations.
bashnpm config list - 2
Update npm Scripts
If any npm scripts in your package.json or global npm scripts are using the '-g' switch, update them to remove this flag. For example, change 'npm install -g package-name' to 'npm install package-name'.
bashsed -i 's/-g //g' package.json - 3
Clear npm Cache
Clear the npm cache to ensure that any cached configurations are removed, which may still reference the deprecated switch.
bashnpm cache clean --force - 4
Reinstall npm
If the issue persists, consider reinstalling npm to ensure that all components are up to date and no deprecated configurations are lingering.
bashnpm install -g npm@latest
Validation
Run 'npm --version' again after completing the steps. If the warning about the deprecated switch '-g' no longer appears, the fix has worked.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep