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

Is there a way to specify the version of npm? #3010

Closed
KerickHowlett opened this issue Jan 18, 2023 · 3 comments
Closed

Is there a way to specify the version of npm? #3010

KerickHowlett opened this issue Jan 18, 2023 · 3 comments

Comments

@KerickHowlett
Copy link

The project I'm developing is running on a much older version of Node (v12), so after installing Node 12, I updated npm out of habit. Now, npm is on v9.3.1, and when I attempt to run any command with it, I get an error that more or less says that npm 9 cannot run on Node v12 (error message pasted below with name of user directory redacted due to security concerns).

ERROR: npm v9.3.1 is known not to run on Node.js v12.7.0. You'll need to upgrade
to a newer Node.js version in order to use this version of npm. This version of
npm supports the following node versions: `^14.17.0 || ^16.13.0 || >=18.0.0`. You
can find the latest version at https://nodejs.org/.

ERROR:
/Users/[USERNAME]/.local/share/nvm/v12.7.0/lib/node_modules/npm/lib/utils/exit-handler.js:21
  const hasLoadedNpm = npm?.config.loaded
                           ^

SyntaxError: Unexpected token .
    at Module._compile (internal/modules/cjs/loader.js:720:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at module.exports (/Users/[USERNAME]/.local/share/nvm/v12.7.0/lib/node_modules/npm/lib/cli.js:81:23)
    at Object.<anonymous> (/Users/[USERNAME]/.local/share/nvm/v12.7.0/lib/node_modules/npm/bin/npm-cli.js:2:25)
    at Module._compile (internal/modules/cjs/loader.js:777:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)

I get the issue of later versions of npm being incompatible with older versions of Node, and that it's like trying to play a 4K Blu-ray on a LaserDisc player, but I would've thought that Node/npm would have something built-in to only install the latest compatible version of npm for any particular version of Node.

Is there a way to control which version of npm is used much in the same way as switching versions of Node?

@ljharb
Copy link
Member

ljharb commented Jan 18, 2023

No, there's not. Duplicate of #964.

To update npm safely, use nvm install-latest-npm, rather than npm install -g npm.

@ljharb ljharb closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2023
@KerickHowlett
Copy link
Author

Oh, okay. Thanks.

@KerickHowlett
Copy link
Author

Sorry for the duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants