FG
🛠️ Developer ToolsMicrosoft

[BUG] `npm.cmd` uses deprecated switch `-g`

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score90%
90%

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

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Remove Deprecated Switch Usage in npm Command

Medium Risk

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. 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.

    bash
    npm config list
  2. 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'.

    bash
    sed -i 's/-g //g' package.json
  3. 3

    Clear npm Cache

    Clear the npm cache to ensure that any cached configurations are removed, which may still reference the deprecated switch.

    bash
    npm cache clean --force
  4. 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.

    bash
    npm 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

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsrelease-8.xbugneeds-triage