Bazel rules_js / rules_nodejs Toolchain Errors in CI
rules_js/rules_nodejs run JS tooling under Bazel via a registered Node toolchain and an npm_translate_lock of your lockfile. Missing toolchain registration, or a lockfile that was never translated, breaks JS rules at analysis time.
What this error means
A js_binary/ts_project target fails with "no toolchain found for @rules_nodejs//nodejs:toolchain_type", or npm packages are unresolved because the lockfile was not translated. Deterministic for the given MODULE.bazel/WORKSPACE.
ERROR: While resolving toolchains for target //app:bundle:
no matching toolchains found for types
@rules_nodejs//nodejs:toolchain_typeCommon causes
Node toolchain not registered
Without registering a Node toolchain (via the rules_nodejs extension in MODULE.bazel or nodejs_register_toolchains in WORKSPACE), Bazel has no Node to run JS actions.
Lockfile not translated to a repo
rules_js needs npm_translate_lock (or the npm extension) pointed at your pnpm-lock.yaml/package-lock.json; without it, @npm//... packages do not exist.
rules_js / rules_nodejs version skew
Incompatible versions between rules_js, aspect_rules_ts, and rules_nodejs can leave the toolchain type unsatisfied.
How to fix it
Register the Node toolchain (bzlmod)
Use the rules_nodejs extension and pin a Node version.
# MODULE.bazel
bazel_dep(name = "rules_nodejs", version = "6.3.0")
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "20.11.1")Translate the lockfile for npm deps
Point the npm extension at your lockfile so @npm//... resolves.
# MODULE.bazel
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")
npm.npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
)
use_repo(npm, "npm")How to prevent it
- Register a Node toolchain explicitly and pin the Node version.
- Keep
npm_translate_lockpointed at a committed lockfile. - Upgrade rules_js, aspect_rules_ts, and rules_nodejs together.