builds are non-deterministic (output file hashes change for no reason)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/nextjs-bug-non-deterministic-builds-ds5czq?file=%2Ftest.sh
To Reproduce
- run the test.sh script (
./test.sh), which should soon make obvious the non-deterministic nature of builds by producing two builds with different files in their outputs, as evidenced by their differing hashes (one ouput is in theoutfolder and another in theout_backfolder).
!!!!!!!!!!!!!!!!!!!!!!!!!! TWO BUILD OUTPUTS ARE DIFFERENT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Only in out_back/_next/static/chunks/app: layout-04f3acfc83f858de.js
Only in out/_next/static/chunks/app: layout-663f360360540d96.js
Current vs. Expected behavior
Expected behavior
All builds should produce the same outputs given that they use the same code and data, that is they should be deterministic.
Current behavior
In this contrived example we demonstrate that it is not the case. The code is very simple (just a layout and a page), there are a few global css files and a few css modules, and already it produces non-deterministic builds, i.e. the hash of some files change between builds, and their content too (although trivially).
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023
Available memory (MB): 4102
Available CPU cores: 2
Binaries:
Node: 20.9.0
npm: 9.8.1
Yarn: 1.22.19
pnpm: 8.10.2
Relevant Packages:
next: 14.2.0-canary.17 // Latest available version is detected (14.2.0-canary.17).
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.3
Next.js Config:
output: export
Which area(s) are affected? (Select all that apply)
App Router, Standalone mode (output: "standalone"), Static HTML Export (output: "export")
Which stage(s) are affected? (Select all that apply)
next build (local), Other (Deployed)
Additional context
As far as I can tell this problem exists since at least Next 13.4.10: https://github.com/vercel/next.js/issues/52827
And the fixes introduced by @wesleydebruijn (https://github.com/vercel/next.js/pull/55358 and https://github.com/vercel/next.js/pull/55425) have mitigated a little the issue by restricting it to css files, but it still exists.
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
Run the linked reproduction's test.sh script and compare the builds in the out and out_back folders, including the differing files under _next/static/chunks/app. Read the referenced issues 52827 and pull requests 55358 and 55425 for prior investigation. Done means repeated builds from the same code and data produce identical outputs and hashes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css, javascript, next.js, react
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100