Skip to content
Latchkey

Node "bad option: --experimental-vm-modules" in CI

Node rejected --experimental-vm-modules as a "bad option". Node flags must be passed as Node options (before the script, or via NODE_OPTIONS), not as arguments to a tool that forwards them to the wrong place.

What this error means

A test script (commonly Jest ESM) fails to start with "node: bad option: --experimental-vm-modules" before any test runs.

node
node: bad option: --experimental-vm-modules

Common causes

The flag reached node as a script argument

Passing the flag after the script name, or through a wrapper that forwards it as a positional arg, makes Node treat it as a bad option.

A Node version that does not support the flag

An older Node that predates --experimental-vm-modules rejects it outright as unknown.

How to fix it

Pass the flag through NODE_OPTIONS

Set it as a Node option so it applies to the Node process that runs the test runner.

package.json
{
  "scripts": {
    "test": "NODE_OPTIONS=--experimental-vm-modules jest"
  }
}

Use cross-env for portability

On runners that include Windows, set the env var with cross-env so the syntax works everywhere.

Terminal
cross-env NODE_OPTIONS=--experimental-vm-modules jest

How to prevent it

  • Pass Node flags via NODE_OPTIONS, not as trailing script args.
  • Use cross-env when env-var syntax must work on Windows runners.
  • Confirm the Node version supports the experimental flag.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →