Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / nodejs

Node.js version is declared

nodejs/version-declared@v1

The project declares the Node.js version it is built and run against, and that version is no older than the configured floor.

Idnodejs/version-declared
Versionv1
Categorynodejs
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsnodejs

Collectors

This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.

CollectorGathersInputs it is given
nodejsThe Node.js project in the project directory: its manifest, the Node version and package manager it asks for, every workspace it declares, the dependencies each manifest names and which of them are pinned, and the lock files committed beside them.projectDir

The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.

Configuration

json
{
  "guardrails": {
      "failOn": "error",
      "comment": true,
      "checks": [
          {
              "use": "nodejs/version-declared@v1",
              "severity": "warning",
              "with": {
                  "projectDir": ".",
                  "minVersion": "18"
              },
              "exemptions": []
          }
      ]
  }
}

Inputs

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR
minVersionOldest Node.js version accepted. A declared version below this is a violation.18GUARDRAIL_INPUT_MINVERSION

How to fix

Declare the runtime where the project already declares itself: "engines": { "node": ">=20" } in package.json, or an .nvmrc file naming the exact release. Without one the runtime is whatever the runner happens to carry, so a syntax or standard library difference reaches CI rather than the laptop that introduced it.

More in nodejs

All 4 nodejs guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412