Skip to content

Prefer node-version-file: package.json over $PATH by default #912

Closed

Description

@fregante

Description:

- uses: actions/setup-node@v5

Currently this uses what's available in $PATH, but I reckon it should prefer what the user already specified as a compatible node version in the package.json.

Justification:

It feels strange that a project clearly and "natively" specifies what version it's expected to run on, but the environment ignores it, requiring further config.

I love that node-version-file: package.json is possible now, but I wish I didn't have to clutter all of my jobs with

- uses: actions/setup-node@v4
  with: 
    node-version-file: package.json

. . . 


- uses: actions/setup-node@v4
  with: 
    node-version-file: package.json

. . .

- uses: actions/setup-node@v4
  with: 
    node-version-file: package.json

The drawback is that in the rare situation where the user wants to use what's in PATH, as opposed to what's in package.json, now they'd need something like node-version: PATH. But again this feels like it should be the minority.

Are you willing to submit a PR?

Potentially

Activity

  1. marko-zivic-93 commented on Dec 11, 2023

    @marko-zivic-93
    Contributor

    Hello @fregante
    Thank you for creating this issue. We will investigate and come back to you as soon as we have some feedback.

  2. v-aparnajyothi-y commented on Jan 9, 2024

    @v-aparnajyothi-y
    Contributor

    Hello @fregante, We've merged the fix for the issue as part of another issue. Could you please try to use actions/setup-node@main to confirm that it works as expected?

  3. v-aparnajyothi-y commented on Jan 18, 2024

    @v-aparnajyothi-y
    Contributor

    Hello @fregante, Thank you for testing.
    Could you please replace the setup-action repository actions/setup-node@v4 in your workflow with actions/setup-node@main because we have merged the code as part of this PR and yet to release.
    Please replace the branch with main and update the results. Hope that should fulfil your requirement.

  4. fregante commented on Jan 18, 2024

    @fregante
    ContributorAuthor

    we have merged the code as part of this PR

    That PR is unrelated to this feature request.

    The tests on main specifically verify the opposite of this feature request, right?

    it('does not read node-version-file if node-version-file is not provided', async () => {
    // Arrange
    delete inputs['node-version-file'];

  5. hilja commented on Jan 19, 2024

    @hilja

    Great issue and great research. I was just wondering the same thing, would be great if the version would just work™

  6. kleinfreund commented on Apr 23, 2024

    @kleinfreund

    Additionally, this would provide a nice way to configure both the node and npm version. Currently, actions/setup-node will install a npm version that does generally not match pkg.engines.npm. If one wants to ensure that the npm version is the same as the one used locally, one has to run npm install --global npm@... after actions/setup-node which is cumbersome.

  7. fregante commented on Apr 23, 2024

    @fregante
    ContributorAuthor

    @kleinfreund that's unrelated, this request is exclusively about changing a default. For what you're asking refer to:

  8. mk-pmb commented on Jun 12, 2024

    @mk-pmb

    I added this one to my suggested way of merging all the version number oracles over here in issue 939.

    I wish I didn't have to clutter all of my jobs with

    The many repetitions of the same "with:" parameters are not specifically related to this one option. It should thus be an issue of its own, and should probably be solved by a config file mechanism.
    The current best stopgap seems to be to make a separate workflow job for installing node, and have your other jobs depend on that.

  9. v-aparnajyothi-y commented on Oct 30, 2025

    @v-aparnajyothi-y
    Contributor

    Hi @y-nk, thank you for this feature request. After internal evaluation and considering existing usage patterns, we've decided to keep the current precedence behavior (node-version > node-version-file). Reversing this logic would be a breaking change for a large number of workflows, and at this time we’re not planning to introduce it as a feature.

    We do recognize the value of the fallback behavior you proposed, especially for monorepo setups. We're closing this issue for now and we'll keep this suggestion in mind for future iterations if we explore safer ways to improve version resolution without impacting backward compatibility.
    Please feel free to reach us in case of any further concerns or clarification to reopen this issue:)

  10. y-nk commented on Oct 30, 2025

    @y-nk

    @aparnajyothi-y i'm not sure to follow why i'm mentioned in @fregante 's issue 🤔

  11. fregante commented on Oct 30, 2025

    @fregante
    ContributorAuthor

    breaking change for a large number of workflows

    Isn't that what semver is for? No CI is going to serendipitously break because the current version remains unchanged.

    What's the point of breaking versions if no breaking changes are allowed?

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

Metadata

Metadata

Assignees

No one assigned

    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