Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
ehoogeveen-medweb opened this issue May 25, 2022 · 6 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@ehoogeveen-medweb
Copy link

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)
@ehoogeveen-medweb ehoogeveen-medweb added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels May 25, 2022
@ehoogeveen-medweb
Copy link
Author

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

@kenbankspeng
Copy link

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

@andmm
Copy link

andmm commented May 29, 2022

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

@ehoogeveen-medweb
Copy link
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.

@ehoogeveen-medweb
Copy link
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.

@ehoogeveen-medweb
Copy link
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
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

3 participants