Repository navigation
Enable caching by default if packageManager field is defined in package.json #686
Description
Activity
- addedfeature requestNew feature or request to improve the current logicNew feature or request to improve the current logic
on Jan 31, 2023 I think the implementation can be as simple as
- if (cache && isCacheFeatureAvailable()) { + const packageManagerFromManifest = getNameFromPackageManagerField(); + if ((cache !== "" || packageManagerFromManifest) && isCacheFeatureAvailable()) { const cacheDependencyPath = core.getInput('cache-dependency-path'); - await restoreCache(cache, cacheDependencyPath); + const packageManager = cache !== "" ? cache : packageManagerFromManifest; + await restoreCache(packageManager, cacheDependencyPath); }
where
getNameFromPackageManagerFieldreturns the package manager name from packageManager field. That is:yarnif the value isyarn@X.Y.Zpnpmis the value ispnpm@X.Y.Z- undefined otherwise
Other package managers can be added, once they are supported
Hello @trivikr ! Thank you for the suggested idea!
We will consider adding this feature and will let you know as soon as we have any decision.Reacted by Nato Boram, Trivikram Kamat and roman zanettinThis is what I doing before this feature landed:
jobs: steps: - name: Checkout uses: actions/checkout@v3 - name: Detect package manager shell: bash run: node -p "'PACKAGE_MANAGER='+require('./package.json').packageManager?.split?.('@')?.[0]" >> "$GITHUB_ENV" - name: Install pnpm run: corepack enable pnpm if: ${{ env.PACKAGE_MANAGER == 'pnpm' }} # install pnpm before setup-node - name: Setup node uses: actions/setup-node@v3 with: node-version: lts cache: ${{ env.PACKAGE_MANAGER }}
Revisiting this, as devEngines has now appeared as a standard in Node.js ecosystem.
It'll be better to track devEngines.packageManager instead of (or in addition to) packageManager field.It's implemented by npm@10.9.0 as well as corepack@0.32.0.
Reacted by v-aparnajyothi-y and Guillaume Humbertv-HarithaVattikuti commented
on Aug 22, 2025 ContributorMore actionsHello Everyone,
We’ve raised PR #1348 to address the above request. Please validate it against the requirement, and confirm to proceed further.
Feel free to reach out if you have any questions or need further clarification.Hello everyone👋,
The requested feature has now been implemented and the related PR#1348 has been merged. This update supports enabling caching when a valid package manager field is detected. To disable this automatic caching, setpackage-manager-cachetofalse.
To utilise this feature, you can use theactions/setup-node@mainbranch in your workflows for now, and the changes will be reflected in the upcoming releases.
We’ll be closing this issue. Please feel free to reach out if you have any further concerns or need additional assistance.
Thanks again for your suggestion and feedback!Reacted by TOMIKAWA Sotaro, Guillaume Humbert, Sʜɪᴍᴜʀᴀ Yū and Jonas ThelemannReacted by Jonas Thelemann and Trivikram KamatRevisiting this, as devEngines has now appeared as a standard in Node.js ecosystem.
It'll be better to track devEngines.packageManager instead of (or in addition to) packageManager field.Was there a particular reason not to look at
devEnginesin https://github.com/actions/setup-node/pull/1348/files#diff-4fab5baaca5c14d2de62d8d2fceef376ddddcc8e9509d86cfa5643f51b89ce3dR139 (e.g. viaconst pm = packageJson.devEngines?.packageManager ?? packageJson.packageManager;) first?Reacted by Daniel Bayley and Derek LindahlHello 👋,
We’re planning to update this feature so that caching is automatically enabled for
npm, while caching will be disabled by default for other package managers (pnpm and yarn). This adjustment is being made based on recent issues withpnpmandyarnintegration. For more background, please see issue #1357.
Our goal with this change is to ensure reliability and prevent failures like those reported for pnpm and yarn. If you have any concerns or suggestions, please share your feedback!Thank you for your understanding and support.
Reacted by Alexander Kachkaev@priyagupta108
Enabling Yarn caching through
actions/setup-node@v5by default will break CI in nodejs/corepack if updated from v4 to v5. This GitHub Actions CI sets the environment variableYARN_ENABLE_GLOBAL_CACHE: false.In a test branch https://github.com/MikeMcC399/corepack/tree/test/setup-node-v5 I simply updated from
actions/setup-node@v4toactions/setup-node@v5and the workflow failed with:Run actions/setup-node@v5 Attempt to resolve LTS alias from manifest... (node:2071) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created) Found in cache @ /opt/hostedtoolcache/node/22.19.0/x64 Environment details /usr/local/bin/yarn --version 1.22.22 /usr/local/bin/yarn cache dir error This project's package.json defines "packageManager": "yarn@4.9.0". However the current global version of Yarn is 1.22.22. 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. Error: error This project's package.json defines "packageManager": "yarn@4.9.0". However the current global version of Yarn is 1.22.22. 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.After disabling cache in a different branch https://github.com/MikeMcC399/corepack/tree/test/setup-node-v5-no-cache with
- uses: actions/setup-node@v5 with: node-version: lts/* package-manager-cache: false
the workflow succeeded.
- Since there is already a PR Limit automatic caching to npm, update workflows and documentation #1374 to disable default caching for Yarn, I won't submit a separate issue for the above.
Hello Everyone, As part of PR #1374, we introduce detection support for
devEngines.packageManager, enabling automatic caching for npm dependencies. This update will be included in the upcoming patch release of v5. We hope this enhancement helps streamline workflows and improve consistency across your projects.Your feedback and suggestions are appreciated. Please take a look and share your thoughts.
- added 4 commits that reference this issue
on Feb 11, 2026 - added a commit that references this issue
on Feb 11, 2026
Description:
The action allows caching global packages data as per documentation in https://github.com/actions/setup-node#caching-global-packages-data
It's an amazing feature and reduces action execution time, but it has to be enabled in configuration.
Caching is not enabled in default setup. Users may not discover caching feature by default, and miss on the faster executions times enabled by caching.
The feature request is to enable caching by default if
packageManagerfield is defined.This can be enabled in a major version bump, say
v4, to not affect existing users.Justification:
Just want all users to get benefit of faster executions times allowed by caching without explicitly opting in, if they have set up packageManager field in their package.json
They can always explicitly opt-out by setting
cacheto empty string.Are you willing to submit a PR?
Yes