Skip to content

[BUG] --location=global does not work from package.json scripts #4945

Closed

Description

@ehoogeveen-medweb

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

I noticed the deprecation warning for --global and changed over to --location=global. However I found that this doesn't work from scripts in package.json. The parameter seems to be silently ignored, whereas --global works and with no deprecation warning. The same thing happens with --location global, -L=global and -L global, all of which work outside package.json scripts.

Expected Behavior

--location=global (and other notations) should work from package.json scripts. I would also expect the deprecation warning to be printed for --global.

Steps To Reproduce

  1. From a fresh npm project (npm init -y).
  2. Set the package.json "test" script to npm install --location=global stylelint.
  3. Run npm run test.
  4. Note that stylelint is installed locally and added as a dependency in package.json.

Environment

  • npm: 8.11.0
  • Node.js: v16.15.0
  • OS Name: Windows 10 (64-bit)

Activity

  1. added
    Bugthing that needs fixing
    Needs Triageneeds review for next steps
    Release 8.xwork is associated with a specific npm 8 release
    on May 25, 2022
  2. ehoogeveen-medweb commented on May 26, 2022

    @ehoogeveen-medweb
    Author

    This issue may be specific to Windows - on Linux I do see the deprecation warning and the dependency is installed globally as expected.

  3. kenbanks-peng commented on May 27, 2022

    @kenbanks-peng

    --location=global is a bit long to type out each time on the command line. IMHO, would be an improvement if some shorter mnemonic could be added, like -g or something...

  4. andmm commented on May 29, 2022

    @andmm

    --location=global is a bit long to type out each time on the command line. IMHO, would be an improvement if some shorter mnemonic could be added, like -g or something...

    Yeah... like it used to be.

  5. ehoogeveen-medweb commented on May 30, 2022

    @ehoogeveen-medweb
    Author

    Confusingly, this does appear to work on a different Windows PC. Same version of Windows, same version of node, same version of npm, same (default) config, same terminal (cmd.exe), so I don't know what could be causing it...

    By the way I agree that there should be at least -L=g in addition to -L=global (and I don't really understand the purpose of deprecating -g), but I think that discussion is beyond the scope of this bug.

  6. ehoogeveen-medweb commented on Jun 3, 2022

    @ehoogeveen-medweb
    Author

    Issue #4989 makes me wonder if this bug is the result of the seemingly indirect way that npm is invoked on Windows.

    In that issue, we see that some module bundled with node v16.15.1 is causing the deprecation warning on every invocation of npm, even versions of npm in which --global is not deprecated (like version 8.12.1).

    In this issue, perhaps the problem is that node v16.15.0 includes an older version of this module which doesn't have support for --location and ends up stripping it out before passing the parameters to npm.

  7. ehoogeveen-medweb commented on Jun 5, 2022

    @ehoogeveen-medweb
    Author

    I figured out the cause of this: I somehow had another version of npm installed at %UserProfile%! It seems that npm run used this version instead of the version in %AppData%\npm.

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

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions