Deterministic npm dependencies with Bazel
Blog post from Aspect Build
Determinism in build systems ensures identical outputs for the same inputs, crucial for optimizing performance in tools like Bazel. Non-determinism, often introduced through npm packages during post-install steps by embedding non-stable elements like timestamps or absolute paths, can lead to inefficient builds, long CI times, and increased costs due to unnecessary rebuilds. This issue is prevalent as npm dependencies often serve as inputs for NodeJS targets, and different npm or yarn installs can result in divergent input hashes, preventing cache sharing across machines. Checking for non-determinism involves comparing outputs from separate runs of npm repository rules, which can reveal differences in generated files that affect build reproducibility. To resolve non-determinism, developers might remove unnecessary non-deterministic files post-install or patch npm dependencies. Regular checks on CI for non-determinism, even after fixing known issues, can prevent regressions and maintain efficient build processes.