Repeatable Gatsby dev environment with Node pinning and lockfiles
0 reputation · 02 Mar 2025, 13:47 UTC
0 reputation · 02 Mar 2025, 13:47 UTC
A team wants a repeatable Gatsby development environment across machines using Node version pinning and a committed dependency lockfile.
The project relies on Gatsby's generated .cache and public directories which are typically gitignored and regenerated on clone. Incremental builds and cache reuse improve speed but add statefulness. The unified GraphQL schema is built from source plugins and local files, and image processing can be affected by file system timestamps and OS differences.
With Node version pinned via .nvmrc or package.json engines and lockfile committed, which build artifacts remain nondeterministic across machines? Does incremental cache state create divergence risk when .cache is not shared? Which outputs should be considered non-reproducible by design?
Even with a pinned Node version (via .nvmrc or engines) and a committed lockfile, several build artifacts remain nondeterministic across different machines. The primary sources of divergence are environment-specific metadata and platform-dependent binary processing.
gatsby-plugin-sharp are not bit-for-bit identical across operating systems. This is due to variations in libvips floating-point behavior, CPU instruction sets (SIMD), and OS-specific color profile handling.public/ Directory: While the logical content is the same, the physical files differ. HTML files often contain build timestamps, and JSON payloads may embed file-system modification times (mtimes) via gatsby-source-filesystem..cache state or environment metadata differs, the resulting hashes for JS and CSS bundles can shift.readdir ordering or file-system stats (like inode hashes or birthtimes).The .cache directory is designed to be machine-specific and should not be shared. Because it stores local file-system metadata and absolute paths, attempting to sync it across machines often leads to build failures or corrupted state.
Does lack of a shared cache create divergence? No, not in terms of functional output. When .cache is absent, Gatsby performs a full rebuild. While this loses the speed of incremental builds and changes the resulting artifact hashes, it does not change the final rendered page content. The risk is not functional divergence, but a lack of binary reproducibility.
To verify the level of divergence in your specific environment, run the following on two different machines (e.g., macOS and Linux) using the same commit:
# Ensure a clean state and strict dependency install
gatsby clean
npm ci
gatsby build
Compare the public/ folders. You will likely find that while the HTML structure is identical, the image binaries and hashed filenames differ.
Are you using any custom source plugins that fetch data from local system environment variables or OS-level APIs? If so, these must be externalized to a .env file to maintain consistency.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.