jestjs/jest · error · Error

Jest: Your version of Node does not support dynamic import -

Error message

Jest: Your version of Node does not support dynamic import - please enable it or use a .cjs file extension for file ${filePath}

What it means

Thrown by `importModule` (requireOrImportModule.ts:36-39) when the underlying dynamic `import()` rejects with the literal `error.message === 'Not supported'`. Node.js emits that exact message on versions where `import()` is disabled or unavailable (e.g. old Node <10, or the `--experimental` flag gating); Jest surfaces a friendlier message pointing at `.cjs` as the workaround.

Source

Thrown at packages/jest-util/src/requireOrImportModule.ts:37

    // node `import()` supports URL, but TypeScript doesn't know that
    const importedModule = await import(
      /* webpackIgnore: true */ moduleUrl.href
    );

    if (!applyInteropRequireDefault) {
      return importedModule;
    }

    if (!importedModule.default) {
      throw new Error(
        `Jest: Failed to load ESM at ${filePath} - did you use a default export?`,
      );
    }

    return importedModule.default;
  } catch (error: any) {
    if (error.message === 'Not supported') {
      throw new Error(
        `Jest: Your version of Node does not support dynamic import - please enable it or use a .cjs file extension for file ${filePath}`,
      );
    }
    throw error;
  }
}

export default async function requireOrImportModule<T>(
  filePath: string,
  applyInteropRequireDefault = true,
): Promise<T> {
  if (!isAbsolute(filePath) && filePath[0] === '.') {
    throw new Error(
      `Jest: requireOrImportModule path must be absolute, was "${filePath}"`,
    );
  }
  try {
    if (filePath.endsWith('.mjs') || filePath.endsWith('.mts')) {

View on GitHub (pinned to f49721c78e)

Solutions

  1. Upgrade Node to a current LTS (>=18) where dynamic `import()` is unconditionally supported.
  2. Rename the target module to `.cjs` so `requireOrImportModule` takes the synchronous `require()` branch instead of `import()`.
  3. If you cannot rename, convert the module to CommonJS (`module.exports = ...`).

Example fix

# before
# jest.config.mjs loaded on Node 10 -> error 214
# after: rename to CommonJS
mv jest.config.mjs jest.config.cjs
Defensive patterns

Strategy: fallback

Validate before calling

// Feature-detect dynamic import before relying on it
const supportsDynamicImport = (() => { try { new Function('return import("data:text/javascript,0")')(); return true; } catch { return false; } })();
if (!supportsDynamicImport) throw new Error('rename target module to .cjs or upgrade Node');

Prevention

When it happens

Trigger: Running Jest on a Node version that lacks dynamic `import()`, or with `--experimental-modules` disabled in a config where dynamic import throws 'Not supported'. Affects any path that falls through to `importModule` (ESM config/resolver/transformer loading).

Common situations: CI pinned to an ancient Node image; an embedded Node runtime that disabled dynamic import; legacy environments predating native ESM. On any modern Node (>=13.2 stable, >=12 with flag) this branch is unreachable.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/00c15c159271dc21.json. Report an issue: GitHub.