Node --experimental-vm-modules Required for ESM Tests in CI - Enable the Flag
Jest evaluates ESM through the Node VM modules API, which is gated behind --experimental-vm-modules. Without the flag, ESM test files fail to load.
What this error means
Running ESM Jest tests in CI fails with a message telling you to run Node with --experimental-vm-modules, and import statements in test files throw before any assertion runs.
node
To enable ECMAScript modules, you must run Node with the
--experimental-vm-modules flag.
SyntaxError: Cannot use import statement outside a moduleCommon causes
Jest ESM support requires the VM modules flag
Jest uses vm.Module to evaluate ES modules, an API still flagged as experimental in Node.
The flag is set locally but not in CI
A developer alias or shell rc adds the flag, but the CI command runs plain jest without it.
How to fix it
Pass the flag via NODE_OPTIONS
- Set NODE_OPTIONS for the test step so Jest can load ESM.
- Run the test command unchanged.
GitHub Actions
- run: jest
env:
NODE_OPTIONS: --experimental-vm-modulesHow to prevent it
- Define the test script with the flag baked in (cross-env NODE_OPTIONS) so CI and local runs use the identical command and ESM test loading never depends on a shell alias.
Related guides
Node "SyntaxError: Unexpected token 'export'" in CI - Fix the Parse ErrorFix the Node.js "SyntaxError: Unexpected token export" in CI by loading the file as ESM or compiling the ESM-…
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 "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…