Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"npm cache hit undefined" #175

Closed
bitttttten opened this issue Mar 23, 2023 · 12 comments Β· Fixed by #188
Closed

"npm cache hit undefined" #175

bitttttten opened this issue Mar 23, 2023 · 12 comments Β· Fixed by #188
Labels

Comments

@bitttttten
Copy link

I am using npm install with two actions and they are never cached, it always says cache hit undefined or failed to save cache.

The workflow file:

name: πŸ‘·πŸ» Linting

on:
  pull_request:
    branches:
      - staging

jobs:
  lint:
    name: ⬣ ESLint
    runs-on: ubuntu-latest
    steps:
      - name: πŸ›‘ Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.11.0

      - name: ⬇️ Checkout repo
        uses: actions/checkout@v3

      - name: βŽ” Setup node
        uses: actions/setup-node@v3
        with:
          node-version-file: '.nvmrc'

      - name: πŸ“₯ Download deps
        uses: bahmutov/npm-install@v1

      - name: πŸ”¬ Lint
        run: npm run lint

  typecheck:
    name: Κ¦ TypeScript
    runs-on: ubuntu-latest
    steps:
      - name: πŸ›‘ Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.11.0

      - name: ⬇️ Checkout repo
        uses: actions/checkout@v3

      - name: βŽ” Setup node
        uses: actions/setup-node@v3
        with:
          node-version-file: '.nvmrc'

      - name: πŸ“₯ Download deps
        uses: bahmutov/npm-install@v1

      - name: πŸ”Ž Type check
        run: npm run types --if-present

And the output:

Run bahmutov/npm-install@v1
running npm-install GitHub Action
trying to restore cached NPM modules
npm cache hit undefined
installing NPM dependencies
npm at "/opt/hostedtoolcache/node/14.17.3/x64/bin/npm"
/opt/hostedtoolcache/node/14.17.3/x64/bin/npm ci

# ....
> npx patch-package

npx: installed 51 in 3.564s
patch-package 6.5.1
Applying patches...
@graphql-codegen/typescript-react-query@3.6.2 βœ”
added 3630 packages in 65.637s
saving NPM modules
/usr/bin/tar --posix -z -cf cache.tgz --exclude cache.tgz -P -C /home/runner/work/repo/repo --files-from manifest.txt
Failed to save: Unable to reserve cache with key npm-linux-x64-xxxxx, another job may be creating this cache. More details: Cache already exists. Scope: refs/pull/1/merge, Key: npm-linux-x64-xxx, Version: xxx
all done, exiting

My first thought is that it is because these are running in parallel, so it's trying to save the cache twice at the same time. Is it worth prefixing each cache keys of npm install in each of these workflows?

@u0reo
Copy link

u0reo commented Apr 4, 2023

As far as I've verified, I've confirmed that the arguments I pass on save have been tampered with, so that might be the culprit.
I don't know why it's been tampered with, but I've added a fix to help prevent tampering.

Try using u0reo/npm-install@fix/restore-failure.

@literat
Copy link

literat commented May 2, 2023

@OpportunityLiu
Copy link

OpportunityLiu commented May 6, 2023

This is caused by @actions/cache, see actions/toolkit#1377

The npmCache.inputPaths is altered in place by the @actions/cache, caused a version mismatch.

A workaround is always sending a copy of npmCache.inputPaths to @actions/cache APIs.

@bitttttten
Copy link
Author

u0reo/npm-install@fix/restore-failure stopped working for me 😒

@oleksandr-danylchenko
Copy link

A workaround is always sending a copy of npmCache.inputPaths to @actions/cache APIs

@OpportunityLiu, could you please provide more details on that? How should this workaround look in the code?

@OpportunityLiu
Copy link

@oleksandr-danylchenko

npm-install/index.js

Lines 32 to 37 in d9c064a

return cache
.restoreCache(
npmCache.inputPaths,
npmCache.primaryKey,
npmCache.restoreKeys
)

npm-install/index.js

Lines 52 to 53 in d9c064a

return cache
.saveCache(npmCache.inputPaths, npmCache.primaryKey)

-  npmCache.inputPaths
+  [...npmCache.inputPaths]

@merlinpaypal
Copy link

Has this been solved? I believe I am getting similar issues.

Interestingly, this only happened after I switched to node 16. On node 14, I have zero issues.

Run bahmutov/npm-install@v1
  with:
    useLockFile: false
running npm-install GitHub Action
trying to restore cached NPM modules
npm cache hit undefined
installing NPM dependencies
npm at "/opt/hostedtoolcache/node/16.[2](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:2)0.0/x64/bin/npm"
/opt/hostedtoolcache/node/16.20.0/x64/bin/npm install
npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated @hapi/topo@[3](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:3).1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/address@2.1.[4](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:5): Moved to 'npm install @sideway/address'
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated consolidate@0.1[5](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:6).1: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated puppeteer@2.1.1: < 19.4.0 is no longer supported
npm WARN deprecated mkdirp@0.5.4: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated debug@3.2.[6](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:7): Debug versions >=3.2.0 <3.2.[7](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:8) || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated chokidar@2.1.[8](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:9): Chokidar 2 does not receive security updates since 201[9](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:10). Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to [10](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:11)0x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated core-js@2.6.[12](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:13): core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.

> @paypal/messaging-components@1.43.0 preinstall
> rm -rf node_modules


added 2606 packages, and audited 2817 packages in 1m

215 packages are looking for funding
  run `npm fund` for details

27 vulnerabilities (1 low, 4 moderate, 15 high, 7 critical)

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
saving NPM modules
/usr/bin/tar --posix -cf cache.tgz --exclude cache.tgz -P -C /home/runner/work/paypal-messaging-components/paypal-messaging-components --files-from manifest.txt -z
Failed to save: Unable to reserve cache with key npm-linux-x64-e0de3175ac4ec0eba5ffe5351fa6cd23e5052f58b5ba974860e8285879bbe63e72ae9ca177fec0065400f15d581724465966f1b0d6923b209a389b0fbe20b537, another job may be creating this cache. More details: Cache already exists. Scope: refs/pull/953/merge, Key: npm-linux-x64-e0de3175ac4ec0eba5ffe5351fa6cd23e5052f58b5ba974860e8285879bbe63e72ae9ca177fec0065400f15d581724465966f1b0d6923b209a389b0fbe20b537, Version: 2da83997b4fe688d9ed687fb56ea866fe123a445363fdf47b3[14](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:15)81fc8be865[41](https://github.com/paypal/paypal-messaging-components/actions/runs/5291312996/jobs/9576686111?pr=953#step:4:42)
all done, exiting

@jphawk
Copy link

jphawk commented Jul 21, 2023

I've started to have the same issue after upgrading from node 16 to node 18.

@Bertg
Copy link
Contributor

Bertg commented Jul 27, 2023

@OpportunityLiu I saw your suggested code change here
@WebeWizard I saw you working on a fork to fix this issue

would any of you be willing to create a PR, increasing the chance that this get fixed, without having to wait for actions/toolkit#1377 to be resolved.
Many other packages are adding their own workaround, so I think it is prudent we help out here.

@bahmutov Pinging you to make you aware of this issue.

@WebeWizard
Copy link
Contributor

@OpportunityLiu I saw your suggested code change here @WebeWizard I saw you working on a fork to fix this issue

would any of you be willing to create a PR, increasing the chance that this get fixed, without having to wait for actions/toolkit#1377 to be resolved. Many other packages are adding their own workaround, so I think it is prudent we help out here.

@bahmutov Pinging you to make you aware of this issue.

Here is the commit that adds the workaround to source. The dist files also need to be updated in this repo. imo, best for the repo author to create.
WebeWizard@005cb4d

@Bertg
Copy link
Contributor

Bertg commented Aug 1, 2023

@bahmutov I've created a PR, containing the source change and update to the dist file. I saw that is how you do it in previous commits as well.

@WebeWizard As the PR is mostly based on your code, I added you as a co-author.

bahmutov pushed a commit that referenced this issue Aug 1, 2023
- closes #175 

An issue in action/toolkit modifies the inputPath values passed to cache function. These changes work around this issue.

For more details see: actions/toolkit#1378

Co-authored-by: Justin Leis <justin.leis@webewizard.com>
@github-actions
Copy link

github-actions bot commented Aug 1, 2023

πŸŽ‰ This issue has been resolved in version 1.8.33 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

literat added a commit to lmc-eu/spirit-design-system that referenced this issue Aug 7, 2023
  * @see bahmutov/npm-install#175
  * the issue with cache miss was resolved and workaround should not be
    used anymore
literat added a commit to lmc-eu/spirit-design-system that referenced this issue Aug 7, 2023
  * @see bahmutov/npm-install#175
  * the issue with cache miss was resolved and workaround should not be
    used anymore
literat added a commit to lmc-eu/spirit-design-system that referenced this issue Aug 7, 2023
  * @see bahmutov/npm-install#175
  * the issue with cache miss was resolved and workaround should not be
    used anymore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants