{"id":"00c15c159271dc21","repo":"jestjs/jest","slug":"jest-your-version-of-node-does-not-support-dynami","errorCode":null,"errorMessage":"Jest: Your version of Node does not support dynamic import - please enable it or use a .cjs file extension for file ${filePath}","messagePattern":"Jest: Your version of Node does not support dynamic import - please enable it or use a \\.cjs file extension for file (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-util/src/requireOrImportModule.ts","lineNumber":37,"sourceCode":"    // node `import()` supports URL, but TypeScript doesn't know that\n    const importedModule = await import(\n      /* webpackIgnore: true */ moduleUrl.href\n    );\n\n    if (!applyInteropRequireDefault) {\n      return importedModule;\n    }\n\n    if (!importedModule.default) {\n      throw new Error(\n        `Jest: Failed to load ESM at ${filePath} - did you use a default export?`,\n      );\n    }\n\n    return importedModule.default;\n  } catch (error: any) {\n    if (error.message === 'Not supported') {\n      throw new Error(\n        `Jest: Your version of Node does not support dynamic import - please enable it or use a .cjs file extension for file ${filePath}`,\n      );\n    }\n    throw error;\n  }\n}\n\nexport default async function requireOrImportModule<T>(\n  filePath: string,\n  applyInteropRequireDefault = true,\n): Promise<T> {\n  if (!isAbsolute(filePath) && filePath[0] === '.') {\n    throw new Error(\n      `Jest: requireOrImportModule path must be absolute, was \"${filePath}\"`,\n    );\n  }\n  try {\n    if (filePath.endsWith('.mjs') || filePath.endsWith('.mts')) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-util/src/requireOrImportModule.ts#L19-L55","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Upgrade Node to a current LTS (>=18) where dynamic `import()` is unconditionally supported.","Rename the target module to `.cjs` so `requireOrImportModule` takes the synchronous `require()` branch instead of `import()`.","If you cannot rename, convert the module to CommonJS (`module.exports = ...`)."],"exampleFix":"# before\n# jest.config.mjs loaded on Node 10 -> error 214\n# after: rename to CommonJS\nmv jest.config.mjs jest.config.cjs","handlingStrategy":"fallback","validationCode":"// Feature-detect dynamic import before relying on it\nconst supportsDynamicImport = (() => { try { new Function('return import(\"data:text/javascript,0\")')(); return true; } catch { return false; } })();\nif (!supportsDynamicImport) throw new Error('rename target module to .cjs or upgrade Node');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run Jest on Node >= 18 LTS.","If you must support old Node, write config/resolvers as `.cjs` (CommonJS).","CI: assert `node --version` meets Jest's engine requirement in a setup step."],"tags":["jest-util","node-version","esm","environment"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}