Skip to content

Allow to set a custom npm version with npm_version option #213

Closed as not planned

Description

@robertsLando

Is there a way to setup the action to use npm 7?

What about npm_version: 7 like actually it's done for node_version?

Activity

  1. maxim-lobanov commented on Dec 7, 2020

    @maxim-lobanov
    Contributor

    Hello!
    npm is integrated to Node.JS.
    NPM 7.x is integrated to Node.JS 15.x. If you specify Node.JS 15.x, NPM 7 will be selected. See details on https://nodejs.org/en/download/releases/

    If you need npm 7 for previous versions of Node.JS, please consider upgrading it in runtime via npm install -g npm@latest

  2. robertsLando commented on Dec 7, 2020

    @robertsLando
    Author

    @maxim-lobanov Would it be possible to make it configurable like I suggested by using an option? It would allow to easily use matrix too

  3. smorimoto commented on Dec 12, 2020

    @smorimoto

    Is it not enough to add npm_version to the matrix and manipulate the workflow? I don't think it's a good idea to add more input than necessary.

  4. mendrik commented on Dec 28, 2020

    @mendrik

    npm publish doesn't work with node 15.x in github actions:

    npm ERR! code ENEEDAUTH
    npm ERR! need auth This command requires you to be logged in.
    npm ERR! need auth You need to authorize this machine using `npm adduser`
    

    when I downgrade to node 12 it works again

  5. dmitry-shibanov commented on Dec 29, 2020

    @dmitry-shibanov
    Contributor

    Hello @mendrik , the issue with publishing is caused by updating npm to 7th version in node 15. The first minor and patch version of npm 7th had the issue with _auth. It was fixed in next versions. You can use npm with node 12th or upgrade npm to the latest one npm install -g npm@latest

  6. Fryuni commented on Jan 15, 2021

    @Fryuni

    It seems setting node-version: 15 now gets a release with the proper fix. It is working without having to update npm

  7. vinayakkulkarni commented on Feb 16, 2021

    @vinayakkulkarni

    Just like we have an option to use node versions, we should also have an option to choose npm versions

  8. fcastilloec commented on Mar 10, 2021

    @fcastilloec

    Using npm install -g npm@latest with Github Actions gives errors regarding write-access permissions. Installing locally npm i npm@latest will change the repository and mess up any actions that depend on a clean git repo. Any ideas on how to fix this? How can I use npm@7 with node@14? Using node@15 is not an option, sorry...

  9. smorimoto commented on Mar 10, 2021

    @smorimoto

    What about doing with sudo?

  10. fcastilloec commented on Mar 10, 2021

    @fcastilloec

    @smorimoto I don't know why I didn't think about it! So, running sudo i -g npm@latest after setup-node action does nothing...
    Here's part of the log (can't provide a link to the full log because it's a private repo):

    2021-03-10T18:20:25.6852244Z ##[group]Run sudo npm i -g npm@latest
    2021-03-10T18:20:25.6852862Z sudo npm i -g npm@latest
    2021-03-10T18:20:25.6906055Z shell: /usr/bin/bash -e {0}
    2021-03-10T18:20:25.6906509Z env:
    2021-03-10T18:20:25.6906931Z   node-version: 14
    2021-03-10T18:20:25.6907390Z ##[endgroup]
    2021-03-10T18:20:37.6677894Z /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
    2021-03-10T18:20:37.6683622Z /usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
    2021-03-10T18:20:37.7550998Z + npm@7.6.2
    2021-03-10T18:20:37.7552906Z added 59 packages from 24 contributors, removed 241 packages and updated 194 packages in 10.209s
    2021-03-10T18:20:37.7743170Z ##[group]Run echo npm version "$(npm --version)"
    2021-03-10T18:20:37.7743827Z echo npm version "$(npm --version)"
    2021-03-10T18:20:37.7744307Z echo node version "$(node --version)"
    2021-03-10T18:20:37.7790961Z shell: /usr/bin/bash -e {0}
    2021-03-10T18:20:37.7791313Z env:
    2021-03-10T18:20:37.7791661Z   node-version: 14
    2021-03-10T18:20:37.7792014Z ##[endgroup]
    2021-03-10T18:20:38.3912711Z npm version 6.14.11
    2021-03-10T18:20:38.3966163Z node version v14.16.0

    You can see that after updating npm to version 7, GitHub Actions still uses version 6. Any ideas what to do?

    I've never had to use sudo before when working with nvm. I'm wondering if updating npm with sudo did it for the system installed version and not the one used by nvm? In order to update the nvm one, we might need to run the command without sudo but that gives us errors about writing permissions...

    SOLUTION: After some trial and error, I figure it out. Updating npm before using this action requires sudo but updating it after using this action doesn't require sudo. As I suspected, when running the command with sudo the system version gets updated, not the one use by this action. So for anybody having the same problem as me, make sure you update npm AFTER running this action and without using sudo

  11. smorimoto commented on Mar 10, 2021

    @smorimoto

    I suspect that the path priority is wrong. The following command should tell you the order, but it probably shows the one installed by the action at the top.

    which --all npm
    

    If it's true, you need to change the priority, but it can be a little tricky. For example, create a new directory, create a symbolic link to npm, and add it to the path through the Actions command.

  12. smorimoto commented on Mar 10, 2021

    @smorimoto

    SOLUTION: After some trial and error, I figure it out. Updating npm before using this action requires sudo but updating it after using this action doesn't require sudo. As I suspected, when running the command with sudo the system version gets updated, not the one use by this action. So for anybody having the same problem as me, make sure you update npm AFTER running this action and without using sudo

    Oh, it's good.

  13. added a commit that references this issue on Mar 29, 2021
  14. 29 remaining items

  15. added a commit that references this issue on Dec 24, 2022
  16. changed the title [-]`npm_version` for npm 7 support[/-] [+]`npm_version` for npm custom version support[/+] on Feb 8, 2024
  17. changed the title [-]`npm_version` for npm custom version support[/-] [+]Allow to set a custom npm version with `npm_version` option[/+] on Feb 8, 2024
  18. robertsLando commented on Feb 8, 2024

    @robertsLando
    Author
  19. nickserv commented on Feb 9, 2024

    @nickserv

    Note that Node is considering removing npm and having corepack install it, which would make this unnecessary if corepack was implemented.

  20. TrejGun commented on Jan 25, 2025

    @TrejGun

    Hey, there!

    On my local machine, I am using macOS with Node installed via NVM. In GitHub Actions, I use the following setup:

    - uses: actions/setup-node@v4
      with:
        node-version: 22
        cache: 'npm'

    I don't actively switch npm versions and rely on the version installed with Node. Apparently, this isn't sufficient because my NX project works locally but fails in CI.

    I found a solution in this Stack Overflow question: link

    - run: npm update

    However, I’m still unsure about which npm version I am actually using and would prefer to control it via the npm_version option.
    I aslo believe it should be called pm_version, and it should also work for other package managers like Yarn.

  21. v-priyagupta108 commented on Aug 31, 2026

    @v-priyagupta108
    Contributor

    Thanks for the request and for the long-running discussion here.

    setup-node provisions the Node.js toolchain, and npm comes bundled with each Node.js distribution. Pinning npm separately would make this action responsible for cache-key correctness, precedence against the packageManager field, and a Node-by-npm compatibility matrix. That's a significant expansion of scope for something already achievable in one step:

    - uses: actions/setup-node@v7
      with:
        node-version: '24'
    - run: npm i -g npm@12   # or npm@latest, or npm@12.0.2 to pin exactly

    This works for older majors as well as newer ones, and keeps the ordering explicit and visible in the workflow.

    Given that, we're not planning to add an npm-version input. Closing as not planned, but happy to revisit if there's a case the workaround genuinely can't cover.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature requestNew feature or request to improve the current logic

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions