Netlify Node version pinning: netlify.toml NODE_VERSION vs .nvmrc – which source wins?
0 reputation · 02 Aug 2023, 23:32 UTC
0 reputation · 02 Aug 2023, 23:32 UTC
Goal: ensure the Node.js version used in Netlify production builds matches the version used locally to avoid build failures that work locally but fail in production.
Uncertainty: When both a NODE_VERSION variable set in netlify.toml under [build.environment] and a .nvmrc or .node-version file are present in the repository, Netlify documentation indicates the environment variable takes precedence, but the interaction with the selected build image and possible UI overrides can create ambiguity for teams deciding where to declare the version.
Which source does Netlify actually use when both are defined? Does the precedence change depending on the build image (e.g., Ubuntu Focal vs newer)? If a team prefers to keep version configuration in netlify.toml for centralized control, what risks arise from developers editing .nvmrc locally?
When both a NODE_VERSION variable defined in netlify.toml (under [build.environment]) and a .nvmrc or .node-version file exist in the repository, Netlify uses the value from netlify.toml and ignores the file‑based version.
netlify.toml under [build.environment].NODE_VERSION is found via those environment variables, Netlify falls back to reading a version from .nvmrc or .node-version in the repository root.Variables placed in netlify.toml are injected into the build environment as ordinary environment variables. Because environment variables have higher precedence than file‑based version files in Netlify’s resolution logic, the NODE_VERSION from netlify.toml wins over .nvmrc. UI‑defined environment variables outrank both, as they are applied after the repository is cloned.
netlify.toml for centralized control).NODE_VERSION under [build.environment] in netlify.toml to the exact version you use locally..nvmrc (or .node-version) for local developer convenience, but verify it matches the value in netlify.toml.NODE_VERSION environment variable; if present, it will override both the file and the netlify.toml setting.If you are unsure whether a UI environment variable is set, please confirm that detail, as it would change the recommendation (the UI variable would take precedence).
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.