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's strict engine check is confusing (when doing npm install npm) #6778

Open
2 tasks done
rotu opened this issue Sep 8, 2023 · 4 comments
Open
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release Release 10.x

Comments

@rotu
Copy link
Contributor

rotu commented Sep 8, 2023

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

npm install --global npm does a strict engine check with some confusing options:

  1. The check is not strictly enforced for non-global installation.

  2. The check is not strictly enforced for npm update --global npm.

  3. The error message shown is generic and there's no indication that the check is due to installing npm in particular.

  4. The check is enforced by the installing npm, not by the install scripts of the version being installed. So the check is not applied when upgrading from npm@6 or when using another package manager such as yarn or pnpm. After installing, the warnings just taunt you that you made a bad decision and don't tell you how to restore npm to a working state.

    npm WARN notsup Unsupported engine for npm@10.0.0: wanted: {"node":"^18.17.0 || >=20.5.0"} (current: {"node":"16.20.2","npm":"6.14.18"})
    npm WARN notsup Not compatible with your version of node/npm: npm@10.0.0

  5. There is no obvious way to do the right thing when upgrading npm, namely installing the newest version compatible with the current node engine. npm install --global npm always resolves to npm@latest.


See npm/template-oss#350 (comment)

Expected Behavior

No response

Steps To Reproduce

  1. In this environment...
  2. With this config...
  3. Run '...'
  4. See error...

Environment

  • npm:
  • Node.js:
  • OS Name:
  • System Model Name:
  • npm config:
; copy and paste output from `npm config ls` here
@rotu rotu added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Sep 8, 2023
@ljharb
Copy link
Contributor

ljharb commented Sep 8, 2023

You're right there's no "install the latest compatible npm" logic; the only place in the ecosystem that captures that rn is nvm's nvm install-latest-npm.

@rotu rotu changed the title [BUG] npm install npm --global strict check is confusing [BUG] npm's strict engine check is confusing (when doing npm install npm) Sep 8, 2023
@ehoogeveen-medweb
Copy link

ehoogeveen-medweb commented Sep 10, 2023

Relatedly (I think): While on node@16 and npm@9,

  • npm outdated -g will list npm@10 in both latest and wanted, even though it's a major version change (which are normally prevented via the semver rules)
  • npm update -g (without specifying npm) will update to npm@10, even though it's not compatible with node@16

Thankfully it still works well enough to downgrade to v9, but I'm concerned about what might happen in future versions!

@ljharb
Copy link
Contributor

ljharb commented Sep 10, 2023

@ehoogeveen-medweb major version changes aren’t prevented by semver rules, it’s that usually package.json has ^ - but there’s no global package.json, so all updates , including breaking changes, are in-range.

I wouldn’t suggest using either command with -g, since there’s no package.json for them. Instead, explicitly update your global deps (for which there should be very few) one at a time.

@ehoogeveen-medweb
Copy link

ehoogeveen-medweb commented Sep 10, 2023

@ljharb The documentation for npm update disagrees:

npm update -g will apply the update action to each globally installed package that is outdated -- that is, has a version that is different from wanted.

Note: Globally installed packages are treated as if they are installed with a caret semver range specified. So if you require to update to latest you may need to run npm install -g [<pkg>...]

In this case wanted points to version 10, in disagreement with the note. I don't know if it's a special exception for npm or if the note is wrong in general. Either way I think wanted should take the node version range into account.

@lukekarrys lukekarrys added the Release 9.x work is associated with a specific npm 9 release label Sep 11, 2023
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 9.x work is associated with a specific npm 9 release Release 10.x
Projects
None yet
Development

No branches or pull requests

4 participants