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: bad option: --experimental-vm-modulesCommon 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.
{
"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.
cross-env NODE_OPTIONS=--experimental-vm-modules jestHow 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.