Skip to content

[BUG] npm.cmd uses deprecated switch -g #4980

Closed

Description

@flensrocker

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When invoking npm --version on Windows there is a warning about a deprecated commandline switch:

❯ npm --version
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
8.12.0

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

Activity

  1. added
    Bug
    Needs Triage
    Release 8.x
    on Jun 2, 2022
  2. AlttiRi commented on Jun 2, 2022

    @AlttiRi

    Same with npm 8.11.0 after installing Node.js v18.3.0. (Node.js v18.2.0 does not have this problem.)
    Using of npx also shows the warning.

  3. nlf commented on Jun 2, 2022

    @nlf
    Contributor

    we've reverted this deprecation in v8.12.1, so i'm closing this issue. thanks for the reports!

  4. yury-tyshkevich commented on Jun 2, 2022

    @yury-tyshkevich

    Not solved!

    PowerShell

    PS C:\> npm -v
    npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
    8.12.1 👈
    PS C:\>
    
  5. adazmy commented on Jun 2, 2022

    @adazmy

    Issue still there on 8.12.1

    npm -v
    npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
    8.12.1
    

    It is solved by editing C:\Program Files\nodejs\npm.cmd
    on line 12
    replacing prefix -g by prefix --location=global

  6. GitSkelly commented on Jun 2, 2022

    @GitSkelly

    Is there a way to re-open this issue or will updates keep coming through this feed?

    I too am having this issue still on 8.12.1.

  7. weezyade commented on Jun 2, 2022

    @weezyade

    I'm having the same issue......on both versions

  8. Dany-GP commented on Jun 3, 2022

    @Dany-GP

    Hi there, I had the same issue, this command solve the bug for me
    npm-windows-upgrade --npm-version latest
    You have to run your powershell or cmd as administrator

  9. Gino16 commented on Jun 3, 2022

    @Gino16

    Issue is still here in npm 8.12.1 version:

    $ npm -v
    npm WARN config global --global, --local are deprecated. Use --location=global instead.
    8.12.1 👀

  10. Dany-GP commented on Jun 3, 2022

    @Dany-GP

    Did you opened command prompt as Administrator? What OS are you running npm? @Gino16

  11. Gino16 commented on Jun 3, 2022

    @Gino16

    I used Git Bash, my OS is Windows 10, its the same result when I open in cmd as Administrator @Dany-GP

  12. Dany-GP commented on Jun 3, 2022

    @Dany-GP

    you can try to set the commands that come here
    npm install --global --production npm-windows-upgrade
    Running this command as admin command prompt should resolve this issue. I recommend you try on administrator cmd.

  13. 54 remaining items

  14. Leandro-FM commented on Jun 13, 2022

    @Leandro-FM

    Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
    npm install -g npm-windows-upgrade
    npm-windows-upgrade

  15. Leandro-FM commented on Jun 13, 2022

    @Leandro-FM

    OK! ok!.. UHUHUHUHHUH.. Obrigado!

  16. Leandro-FM commented on Jun 13, 2022

    @Leandro-FM

    Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
    npm install -g npm-windows-upgrade
    npm-windows-upgrade

    // Resolvido
    PS C:\WINDOWS\system32> 8.12.1
    PS C:\WINDOWS\system32> PS C:\WINDOWS\system32>^C
    PS C:\WINDOWS\system32> 8.12.1
    PS C:\WINDOWS\system32> npm -v
    8.12.1
    PS C:\WINDOWS\system32>

  17. ashifbabu commented on Jun 13, 2022

    @ashifbabu

    It is solved by editing C:\Program Files\nodejs\npm.cmd
    on line 12
    replacing prefix -g by prefix --location=global

    It works ;)

    It works for me too

    Finally works 👍 :) Thanks

  18. IMDanijel commented on Jun 17, 2022

    @IMDanijel

    Is there an existing issue for this?

    • I have searched the existing issues

    This issue exists in the latest npm version

    • I am using the latest npm

    Current Behavior

    When invoking npm --version on Windows there is a warning about a deprecated commandline switch:

    ❯ npm --version
    npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
    8.12.0
    

    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

    **This worked for me,
    Run CMD as Administrator:

    C:/WINDOWS/system32>npm-windows-upgrade --npm-version latest
    npm-windows-upgrade v6.0.1
    Checked system for npm installation:
    According to PowerShell: C:\Program Files\nodejs
    According to npm: C:\Users\Admin\AppData\Roaming\npm
    Decided that npm is installed in C:\Program Files\nodejs
    Upgrading npm.../

    Upgrading npm (fallback method)... |

    Upgrade finished. Your new npm version is 8.12.2. Have a nice day!

    C:\WINDOWS\system32>npm -v
    8.12.2

  19. arantisi commented on Jul 2, 2022

    @arantisi

    im having this issue as well what do i do ?
    image

  20. flensrocker commented on Jul 3, 2022

    @flensrocker
    Author

    As Administrator run

    npm i -g npm-windows-upgrade
    npm-windows-upgrade
    
  21. yangjunran commented on Jul 6, 2022

    @yangjunran

    1657120836624

  22. woorykim commented on Jul 27, 2022

    @woorykim
    1. npm i -g npm-windows-upgrade
    2. npm-windows-upgrade
    3. If the above problem persists, use the following methods:
      (feat. @Hashsudo - Thanks! UHUH~~~~ Thank for you solve!🧙‍♂️)

    언급된 단계를 사용하여 해결할 수 있었습니다. 다른 사람들이 Powershell 관리자를 사용하여 나와 유사한 문제를 경험하는 경우 스크린샷을 제공하겠습니다. 대단히 감사하는 flensrocker! 이것이 다른 사람들을 돕기를 바랍니다.

    1 단계: 스크린샷_2

    2 단계: 스크린샷_3

    3단계: 스크린샷_4

    4단계: png) 스크린샷_5

  23. snebjorn commented on Oct 12, 2022

    @snebjorn
    PS> npm --version
    npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
    8.19.2
    
    
    PS> node -v
    v16.16.0
    
    
    PS> Get-Command npm
    
    CommandType     Name                                               Version    Source
    -----------     ----                                               -------    ------
    Application     npm.cmd                                            0.0.0.0    C:\Program Files\nodejs\npm.cmd
    
    
    PS> Get-ComputerInfo OsName,OsVersion,OsBuildNumber,OsHardwareAbstractionLayer,WindowsVersion
    
    OsName                     : Microsoft Windows 11 Enterprise
    OsVersion                  : 10.0.22000
    OsBuildNumber              : 22000
    OsHardwareAbstractionLayer : 10.0.22000.778
    WindowsVersion             : 2009

    Is the official fix for this error to run the following?

    npm i -g npm-windows-upgrade
    npm-windows-upgrade
    

    Or will this be fixed in via an update? So we can just run npm i -g npm

  24. flensrocker commented on Oct 12, 2022

    @flensrocker
    Author

    @snebjorn As I understand the installation of npm on Windows, npm i -g npm will never work, see the official documentation.

    npm-windows-upgrade is the way to go.

  25. HucklJS commented on Dec 11, 2022

    @HucklJS

    I just upgraded npm by opening C:\Program Files\nodejs as administrator in PowerShell and running npm install npm. No more warnings during version check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageRelease 8.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions