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] npm v 8.11.0 - writes to STDERR - "npm WARN config global --global, --local ..." breaking our nightly build process. #4989

Closed
2 tasks done
raven1152 opened this issue Jun 2, 2022 · 7 comments
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

@raven1152
Copy link

raven1152 commented Jun 2, 2022

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

current version of npm (8.11.0, node 16.15.1) writes a warning to STDERR on every command, that is a warning about using deprecated options. The message is...

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

The message is written to STDERR regardless of whether or not the command run uses the --global or --local options. For example, the command...

npm -v

outputs the message, even though -v is the only option used, and writes to STDERR, even though it states it's purpose to be a warning, not an error, and the command still executes successfully.

The result for my organization is to break our nightly builds. Our builds need to monitor STDERR for REAL build errors, which also use STDERR to capture a variety of aberrant build conditions including security vulnerabilities that are reported back to the build pipeline via STDERR in a script that runs "npm audit" and analyzes the results.

npm-warn

Expected Behavior

IMHO, this warning should only be written if the deprecated options are used, and should be written to STDOUT since it is not an error, just a warning.

Steps To Reproduce

  1. In Windows...
  2. Running node 16.15.1 and npm 8.11.0
  3. Run any npm command, i.e. npm -v
  4. See results...
    npm output

Environment

  • npm: 8.11.0
  • Node.js: 16.15.1
  • OS Name: Windows 10
  • System Model Name: Dell Precision 5500 series
  • npm config:
; "user" config from C:\Users\xxxx\.npmrc

cafile = "C:\\cert\\OGS_int_CA.pem"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v16.15.1
; npm local prefix = C:\Users\xxxx
; npm version = 8.11.0
; cwd = C:\Users\xxxx
; HOME = C:\Users\xxxx
; Run `npm config ls -l` to show all defaults.
@raven1152 raven1152 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 Jun 2, 2022
@ehoogeveen-medweb
Copy link

ehoogeveen-medweb commented Jun 3, 2022

This issue seems to be coming from Node.js itself!

  • With node v16.15.1 I get this warning for every invocation of npm, even with npm 8.12.1 (which undeprecates --global)
  • With node v16.15.0 I don't get this warning, even with npm 8.11.0 (which deprecated --global)

I also only see the issue on Windows.

Edit: FWIW, the warning also triggers regardless of what is passed to npm - even explicitly passing --location=global or some other --location doesn't help. I think some dependency bundled with the release of Node.js v16.15.1 includes the deprecation warning, and updating the installed version of npm doesn't update this dependency (which may be a bug in and of itself?).

@XhmikosR
Copy link
Contributor

XhmikosR commented Jun 5, 2022

This was fixed by #4982 and it's included in v8.12.1.

You should bug the Node.js people to update the bundled npm there if it's not already done and cut a new version. Alternatively, you can update your npm instance until the issue is fixed in Node.js.

@ehoogeveen-medweb
Copy link

ehoogeveen-medweb commented Jun 5, 2022

Here's a workaround until Node.js v16.15.2 is released:

  1. Open a Windows PowerShell command window with elevated privileges (an administrative prompt).
  2. Run the following commands (assuming the default installation directory was used for Node.js):
(Get-Content "${Env:ProgramFiles}\nodejs\npm.cmd") -replace '-g','-L=global' | Out-File -Encoding ascii "${Env:ProgramFiles}\nodejs\npm.cmd"
(Get-Content "${Env:ProgramFiles}\nodejs\npx.cmd") -replace '-g','-L=global' | Out-File -Encoding ascii "${Env:ProgramFiles}\nodejs\npx.cmd"

The problem here happens because the version of npm in the Node.js installation directory is used to get the global prefix. After that, processing is handed over to the global version of npm, but by that point the warning has already been printed. The version of npm in the Node.js installation directory does not get updated when you run npm install -g npm@latest.

Edit: Looks like this is still needed for Node.js v16.16.0!

@raven1152
Copy link
Author

Thank you @ehoogeveen-medweb I have forwarded this to our build-master so they can implement the fix. I appreciate your time in taking a look at this.

@tussar01
Copy link

Thanks

@K3NZ11
Copy link

K3NZ11 commented Aug 6, 2022

I tried the workaround from @ehoogeveen-medweb and it removed the warning only for Powershell. In my case, I was also using GitBash, and the npm command was executing from a different directory.

# PowerShell -> C:\Program Files\nodejs\npm.cmd
Get-Command npm
# Git Bash -> C:\Program Files\nodejs\npm
which npm

Therefore, to apply this workaround for GitBash, you need to update the following files.

# Git Bash
sed -i 's/-g/-L=global/g' "C:/Program Files/nodejs/npm"
sed -i 's/-g/-L=global/g' "C:/Program Files/nodejs/npx"

@K3NZ11
Copy link

K3NZ11 commented Aug 6, 2022

Upgrading Node.js to the CURRENT version that included npm v8.15.0 might also remove this deprecated warning.

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

5 participants