Node Build Flag Rejected as "bad option" in CI - Fix the Build Invocation
A build that injects extra Node flags (heap size, loaders, experimental features) fails immediately when the runner Node does not recognize one of them.
What this error means
A build step exits at once with node: bad option: <flag>, because a build script or NODE_OPTIONS passes a flag the CI Node version rejects.
node
> cross-env NODE_OPTIONS='--max-old-space-size=4096 --loader ts-node/esm' vite build
node: bad option: --loader ts-node/esm
$ exit status 9Common causes
A removed or renamed flag in NODE_OPTIONS
A build sets a flag (like an old loader spelling) that the current Node no longer accepts.
A version skew between local and CI Node
The build flags suit the local Node but the CI runner runs a version that rejects them.
How to fix it
Align the Node version with the flags
- Pin the CI Node version to one that accepts the build flags.
- Re-run the build.
GitHub Actions
- uses: actions/setup-node@v4
with:
node-version: 20Update the flags to the supported form
- Replace removed flags (for example --loader) with the supported equivalent (--import).
- Re-run with the corrected NODE_OPTIONS.
How to prevent it
- Keep build-time NODE_OPTIONS in sync with the pinned CI Node version, and update flags when Node deprecates or removes them.
Related guides
Node "bad option" Unknown Flag in CI - Fix the Node InvocationFix the Node.js "bad option" unknown-flag error in CI by removing the flag, fixing its spelling, or using a N…
Node "ExperimentalWarning: --loader is deprecated" in CI - Switch to --importFix the Node.js "--loader is deprecated" experimental warning in CI by moving to the --import flag with modul…
Node "FATAL ERROR: Reached heap limit Allocation failed" in CI - Fix the OOMFix the Node.js "FATAL ERROR: Reached heap limit Allocation failed" out-of-memory crash in CI by raising the…