jestjs/jest · error · Error

jest.config.mts requires native TypeScript support. Ensure y

Error message

jest.config.mts requires native TypeScript support. Ensure you are using Node.js 22.18+ or 23.6+.

What it means

Jest config files ending in .mts are always ESM and cannot be loaded via require() or ts-node. Jest first attempts native Node TypeScript support (process.features.typescript, available on Node 22.18+ / 23.6+). If that import fails for a .mts file there is no fallback loader, so this hard error is thrown pointing at the Node version requirement.

Source

Thrown at packages/jest-config/src/readConfigFileAndSetRootDir.ts:55

    configPath.endsWith(JEST_CONFIG_EXT_TS) ||
    configPath.endsWith(JEST_CONFIG_EXT_MTS) ||
    configPath.endsWith(JEST_CONFIG_EXT_CTS);
  const isMTS = configPath.endsWith(JEST_CONFIG_EXT_MTS);
  const isJSON = configPath.endsWith(JEST_CONFIG_EXT_JSON);
  let configObject;

  try {
    if (isTS) {
      // .mts is always ESM, so attempt import-based loading first.
      // @ts-expect-error: Type assertion can be removed once @types/node is updated to 23 https://nodejs.org/api/process.html#processfeaturestypescript
      if (isMTS || process.features.typescript) {
        try {
          // Try native node TypeScript support first.
          configObject = await requireOrImportModule<any>(configPath);
        } catch (requireOrImportModuleError) {
          if (isMTS) {
            // .mts is always ESM and cannot be loaded via require()/ts-node.
            throw new Error(
              'jest.config.mts requires native TypeScript support. Ensure you are using Node.js 22.18+ or 23.6+.',
              {cause: requireOrImportModuleError},
            );
          }
          if (!(requireOrImportModuleError instanceof SyntaxError)) {
            if (!hasTsLoaderExplicitlyConfigured(configPath)) {
              throw requireOrImportModuleError;
            }
          }
          try {
            // There are various reasons of failed loadout of Jest config in Typescript:
            // 1. User has specified a TypeScript loader in the docblock and
            // desire non-native compilation (https://github.com/jestjs/jest/issues/15837)
            // 2. Likely ESM in a file interpreted as CJS, which means it needs to be
            // compiled. We ignore the error and try to load it with a loader.
            configObject = await loadTSConfigFile(configPath);
          } catch (loadTSConfigFileError) {
            // If we still encounter an error, we throw both messages combined.

View on GitHub (pinned to f49721c78e)

Solutions

  1. Upgrade Node to 22.18+ or 23.6+ (or any later release that ships native TypeScript)
  2. Rename the config to jest.config.ts or jest.config.cts so the ts-node/esbuild-register fallback path applies
  3. Run Node with --experimental-strip-types if on a version that supports it but does not enable it by default

Example fix

// before: jest.config.mts on Node 20
export default {testEnvironment: 'node'};
// after option A: upgrade Node to 22.18+
// after option B: rename to jest.config.cts
module.exports = {testEnvironment: 'node'};
Defensive patterns

Strategy: validation

Validate before calling

import * as semver from 'semver';
function nodeSupportsNativeTS(): boolean {
  return Boolean((process as any).features?.typescript) ||
    semver.gte(process.version, '22.18.0') ||
    semver.gte(process.version, '23.6.0');
}
if (configPath.endsWith('.mts') && !nodeSupportsNativeTS()) {
  throw new Error('Upgrade Node to 22.18+ for jest.config.mts');
}

Prevention

When it happens

Trigger: Using a jest.config.mts file on Node < 22.18 (or < 23.6 on the 23 line), or on a Node build compiled without the experimental TypeScript flag enabled.

Common situations: Upgrading a project to ESM and renaming jest.config.ts to jest.config.mts while the CI Node version lags; local dev using an older Node via nvm; corporate Node LTS pinning.

Related errors


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