GeezerVison is showing github.com — Allow to set a custom npm version with `npm_version` option · Issue #213 · actions/setup-node
Allow to set a custom npm version with npm_version option #213DescriptionIs there a way to setup the action to use npm 7?
What about npm_version: 7 like actually it's done for node_version? Reacted by Merwan Rodriguez, Seghir Nadir, Sandor, RoboPhred, Iddan Aaronsohn, Mykhailo Gorianskyi, Tiago de Souza Santos, Andreas Herd, Chee Aun, Moritz Wolf and 123 more Activitymaxim-lobanov commented on Dec 7, 2020 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 Reacted by loucadufault, sandstrom and HermannGruber robertsLando commented on Dec 7, 2020 @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 smorimoto commented on Dec 12, 2020 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. Reacted by Daniel Lando, Sean, Roma(nna) Koval and Ryan Wilke mendrik commented on Dec 28, 2020 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 dmitry-shibanov commented on Dec 29, 2020 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 Reacted by Andreas Herd, David Vurbs and Rico Kahler Fryuni commented on Jan 15, 2021 It seems setting node-version: 15 now gets a release with the proper fix. It is working without having to update npm Reacted by Jonathan Prass Martins Reacted by Jeong Jinwoo, Andreas Herd, hata6502 and Jonathan Prass Martins vinayakkulkarni commented on Feb 16, 2021 Just like we have an option to use node versions, we should also have an option to choose npm versions Reacted by Busticated, Jason Adams, Peter Juras, Felipe Castillo, parachvte, Nigel Jones, Thomas Mullen, Vladyslav Zubko, Johnson Liang, Jayden Seric and 85 more Reacted by Joe Pea, Hui Chang, Daniel Lando, René Eschke, Dmitri, Pascal Betting, Param Siddharth, Ivan Coronado, yaeszlo, tystar and 8 more fcastilloec commented on Mar 10, 2021 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... Reacted by Kang Huang, Alex Bea, Dmitri and Dan Stanley smorimoto commented on Mar 10, 2021 What about doing with sudo? Reacted by Felipe Castillo, David Wheatley, Mingwei Samuel, Brad Ackerman and Mario Kozjak fcastilloec commented on Mar 10, 2021 @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 + [email protected]
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 Reacted by Nelson Martell, Yehyoung Kang, Arun Reddy, AkshayRajput, Wildan M, Tom Zhang, Christopher Hirt, electrovir and José Pacheco smorimoto commented on Mar 10, 2021 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.
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. smorimoto commented on Mar 10, 2021
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. changed the title [-]`npm_version` for npm 7 support[/-] [+]`npm_version` for npm custom version support[/+] on Feb 8, 2024changed the title [-]`npm_version` for npm custom version support[/-] [+]Allow to set a custom npm version with `npm_version` option[/+] on Feb 8, 2024robertsLando commented on Feb 8, 2024 nickserv commented on Feb 9, 2024 Note that Node is considering removing npm and having corepack install it, which would make this unnecessary if corepack was implemented. TrejGun commented on Jan 25, 2025 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
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. Reacted by Mikey Gray, José Pacheco and Caio Augusto Araújo Oliveira v-priyagupta108 commented on Aug 31, 2026 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 [email protected] 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. Reacted by fregante, Will Slattum and Nicky McCurdy
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|