setup-node: Node setup fails non-deterministically with Yarn starting on November 17th
Description:
When using the “setup-node” action, CI non-deterministically fails, meaning that sometimes, I get no errors, and other times, I get errors.
Here is an example CI run where you can see the failures: https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354
Specifically, the output is as follows:
Prepare all required actions
Getting action download info
Download action repository 'actions/setup-node@v4' (SHA:8f15[2](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:2)de45cc[3](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:3)93bb[4](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:4)8ce[5](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:5)d89d3[6](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:7)b731f54556e65)
Download action repository 'actions/cache@v3' (SHA:704facf57e6[13](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:15)6b1bc63b828d79edcd491f0ee84)
Run ./.github/workflows/setup
Run actions/setup-node@v4
Found in cache @ /opt/hostedtoolcache/node/20.9.0/x64
Environment details
/usr/local/bin/yarn --version
1.22.21
/usr/local/bin/yarn cache dir
error This project's package.json defines "packageManager": "yarn@4.0.2". However the current global version of Yarn is 1.22.21.
Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and [14](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:16).[19](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:22).
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
Error: error This project's package.json defines "packageManager": "yarn@4.0.2". However the current global version of Yarn is 1.22.[21](https://github.com/IsaacScript/isaacscript/actions/runs/6907352290/job/18794331354#step:3:24).
Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
Thus, we can see that this GitHub Action is failing to install Yarn properly, since Yarn appears to be version 1 instead of version 4.
For more context, we can see that this repository has a GitHub Actions matrix set up where it spawns N jobs and all of the jobs use “setup-node”. Thus, since there are some green checkmarks and some red checkmarks, we can see that it fails randomly, and the specific checkmarks that appear are randomized with every commit to the repository.
Action version: 4
Platform:
- Ubuntu
- macOS
- Windows
Runner type:
- Hosted
- Self-hosted
Tools version: yarn v4.0.2
More info: I started seeing this error today, with no other related CI code changes, so the problem is likely to come from this action (or the GitHub Action VM) and not my actual code-base.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 34
- Comments: 22 (1 by maintainers)
Commits related to this issue
- fix: try fix yarn version issue see https://github.com/actions/setup-node/issues/899#issuecomment-1817757655 and https://nodejs.org/api/corepack.html#configuring-a-package — committed to ast-grep/ast-grep by HerringtonDarkholme 3 years ago
- Skip the `corepack` check - https://github.com/actions/setup-node/issues/899 — committed to akunzai/svelte-boilerplate by akunzai 3 years ago
- Skip the `corepack` check - https://github.com/actions/setup-node/issues/899 — committed to akunzai/react-boilerplate by akunzai 3 years ago
- Skip the `corepack` check - https://github.com/actions/setup-node/issues/899 — committed to akunzai/angular-boilerplate by akunzai 3 years ago
- chore: Enable corepack before setting up node See https://github.com/actions/setup-node/issues/899 When defining `packageManager` in package.json, github runners will now error about using the wrong... — committed to GlareDB/glaredb by scsmithr 3 years ago
- chore: Enable corepack before setting up node (#2146) See https://github.com/actions/setup-node/issues/899 When defining `packageManager` in package.json, github runners will now error about usin... — committed to GlareDB/glaredb by scsmithr 3 years ago
- build: try to fix the push build This should work around this issue: https://github.com/actions/setup-node/issues/899 Solution from: https://github.com/actions/setup-node/issues/899#issuecomment-18... — committed to mikavilpas/parjs by barona-mika-vilpas 3 years ago
- fix: workaround for actions/setup-node#899 — committed to jgraichen/redmine_dashboard by jgraichen 3 years ago
- fix: workaround for actions/setup-node#899 — committed to mnemosyne-mon/mnemosyne-server by jgraichen 3 years ago
- ci: workaround for corepack See https://github.com/actions/setup-node/issues/899#issuecomment-1828798029 — committed to catppuccin/vscode by nekowinston 3 years ago
- ci: workaround for corepack See https://github.com/actions/setup-node/issues/899#issuecomment-1828798029 — committed to catppuccin/vscode by nekowinston 3 years ago
- ci(root): fixed the problem on the GitHub Actions In CI/CD, the "setup-node" action sometimes fails to resolve the Yarn version. This problem is solved by opting for corepack beforehand. see: https:... — committed to kurone-kito/lints-config by kurone-kito 3 years ago
- ci(root): fixed the problem on the GitHub Actions In CI/CD, the "setup-node" action sometimes fails to resolve the Yarn version. This problem is solved by opting for corepack beforehand. see: https:... — committed to kurone-kito/lints-config by kurone-kito 3 years ago
- run corepack before actions/setup-node https://github.com/actions/setup-node/issues/899 — committed to AndroidDagashi/androiddagashi.github.io by yshrsmz 3 years ago
- fix actions/setup-node#899 — committed to hugefiver/mystars by hugefiver 3 years ago
- Fixes ci.yml. See: https://github.com/actions/setup-node/issues/899#issuecomment-1828798029 — committed to term-finance/term-finance-contracts by robotoer 3 years ago
- Fixes ci.yml. See: https://github.com/actions/setup-node/issues/899#issuecomment-1828798029 — committed to term-finance/term-finance-contracts by robotoer 3 years ago
- Moving corepack enable before calling setup-node. See: https://github.com/actions/setup-node/issues/899 Signed-off-by: cmoulliard <cmoulliard@redhat.com> — committed to q-shift/backstage-plugins by cmoulliard 3 years ago
- Initial refactoring of the github workflow to publish modules on npmjs Signed-off-by: cmoulliard <cmoulliard@redhat.com> Set dry run to test the github flow Signed-off-by: cmoulliard <cmoulliard@re... — committed to q-shift/backstage-plugins by cmoulliard 3 years ago
- Initial refactoring of the github workflow to publish modules on npmjs Signed-off-by: cmoulliard <cmoulliard@redhat.com> Set dry run to test the github flow Signed-off-by: cmoulliard <cmoulliard@re... — committed to q-shift/backstage-plugins by cmoulliard 3 years ago
As @Mause mentioned, this can be temporarily solved by enabling Corepack before running
setup-node.I was stuck with the same problem. However, putting the Yarn binary in Git management with the following command helped me:
This is not ideal, because actions/checkout it designed for carrying out git commands, so you can’t be sure that
nodeis present, or that it has the correct version you are specifying in the next step with Node 16 at least required forcorepack. Instead I have managed to workaround this issue by running two steps:This will setup Node to version 20, run corepack enable, then setup the cache
Committing the Yarn binary to the repo is a good workaround for now, thanks. However, note that doing this is discouraged in Yarn version 4, as the ecosystem should use corepack going forward. So I would love a solution to this
setup-nodeissue sooner rather than later.Hello @Zamiell , According to my analysis, it seems that the discrepancy between Yarn versions (1.22.19 vs 1.22.21) in different jobs is causing the issue you’re encountering. As per the release notes for Yarn version 1.22.20, a notice will be displayed when Yarn 1.22 identifies a
package.jsonfile in the project that references a non-1.x Yarn release using thepackageManagerfield. In this situation, the Yarn version in runner images was updated from v1.22.19 to v1.22.21 on November 16, which potentially led to the display of this error message afterwards. At the present moment, the repository doesn’t provide functionality to compare Yarn versions between the global scope and the one specified in the package.json. This feature could be incorporated for future enhancements to the repository. I am going to proceed with closing it. I appreciate your understanding and patience. Many thanks!@felladrin Yea, that’s better and actually caches my Yarn deps. Setting
SKIP_YARN_COREPACK_CHECK=1and runningcorepack enableaftersetup-nodewas not caching anything.I believe the action runner image contains a copy of node, as most actions are themselves written in JavaScript (including this one I think?)
Downgrade to yarn@1.22.19 work for me,
npm install -g yarn@1.22.19If you don’t want to commit the Yarn version you can setdon’t do this,SKIP_YARN_COREPACK_CHECK=1to skip this check. Then later in steps runcorepack enable.setup-nodewont cache your deps.If you have investigated the issue, can you explain why the error only happens sometimes, and not other times? Naively, I would expect that to indicate some kind of bug in either this GitHub action or the GitHub runner virtual machine.
Furthermore, Yarn 4 was released on October 22nd, 2023, and this GitHub Actions issue started occurring on November 17th, 2023. Which means that Yarn 4 worked just fine with this action for 26 days. Thus, I find your classification of the race condition described in the OP as a “feature request” rather than an “bug” completely baffling. Can you explain further why it is a “feature request” to request that something that already worked continues to work in the same way?
Hey @Zamiell , as per my previous comment, we will consider this issue as an enhancement in future. Feel free to share your inputs !!!
Hello @Zamiell , just a gentle ping!
Can confirm @kurone-kito solution works as a workaround for this 🎉