Next.js Cache not working with CircleCI
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/DoctrineLegal/nextjs-cache-issue/blob/master/README.md
To Reproduce
- Trigger a build on CircleCI
- Cache it's .next directory
- Re-trigger a build on CircleCI with a hot cache
- See that next.js is not using the cache
Current vs. Expected behavior
Current behavior: https://app.circleci.com/pipelines/github/DoctrineLegal/nextjs-cache-issue/1/workflows/745158ac-1c40-448e-9083-391e90cb0938/jobs/1
CircleCI is not using the cache. And consistently taking the same time to build.
Expected Behavior: https://app.circleci.com/pipelines/github/DoctrineLegal/nextjs-cache-issue/1/workflows/745158ac-1c40-448e-9083-391e90cb0938/jobs/1
CircleCI should use the cache as specified here : https://nextjs.org/docs/pages/building-your-application/deploying/ci-build-caching#circleci
When forcing the cache dir it actually works.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.0.0: Tue Sep 24 23:38:45 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T8122
Available memory (MB): 16384
Available CPU cores: 8
Binaries:
Node: 22.4.1
npm: 10.8.1
Yarn: 1.22.22
pnpm: 9.15.0
Relevant Packages:
next: 15.0.4-canary.46 // There is a newer canary version (15.0.4-canary.48) available, please upgrade!
eslint-config-next: 15.0.2
react: 19.0.0-rc-02c0e824-20241028
react-dom: 19.0.0-rc-02c0e824-20241028
typescript: 5.6.3
Next.js Config:
output: N/A
⚠ There is a newer canary version (15.0.4-canary.48) available, please upgrade!
Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
Read more - https://nextjs.org/docs/messages/opening-an-issue
Which area(s) are affected? (Select all that apply)
Performance, Webpack
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
CircleCI is indeed running on docker with a cgroup container docker : https://github.com/vercel/next.js/blob/canary/packages/next/src/compiled/is-docker/index.js and found as docker from this file.
I believe this PR : https://github.com/vercel/next.js/pull/70516 from @shuding introduced the issue.
As a side note : CircleCI is currently rolling out new containers that will not be subject to this issue : https://discuss.circleci.com/t/docker-executor-infrastructure-upgrade/52282
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction repository's README and the CircleCI workflow described in the issue, then inspect packages/next/src/compiled/is-docker/index.js and PR #70516. Reproduce the cache behavior with a hot CircleCI cache and compare it with the configuration that forces the cache directory. Done means the documented CircleCI cache is used reliably without forcing the directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, javascript, nextjs
- Domain
- build-system, ci-cd, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100