jestjs/jest · error · Error

Jest: Failed to parse the TypeScript config file ${configPat

Error message

Jest: Failed to parse the TypeScript config file ${configPath}
  ${error}

What it means

The outer catch-all in readConfigFileAndSetRootDir wraps any failure to load a TypeScript config file with the offending path and the underlying error. It commonly wraps the combined 'both native and loader failed' string thrown from the inner try, surfacing both failure reasons together. It fires only for .ts/.mts/.cts configs.

Source

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

              '  both with the native node TypeScript support and configured TypeScript loaders.\n' +
              '    Errors were:\n' +
              `    - ${requireOrImportModuleError}\n` +
              `    - ${loadTSConfigFileError}`
            );
          }
        }
      } else {
        configObject = await loadTSConfigFile(configPath);
      }
    } else if (isJSON) {
      const fileContent = fs.readFileSync(configPath, 'utf8');
      configObject = parseJson(stripJsonComments(fileContent), configPath);
    } else {
      configObject = await requireOrImportModule<any>(configPath);
    }
  } catch (error) {
    if (isTS) {
      throw new Error(
        `Jest: Failed to parse the TypeScript config file ${configPath}\n` +
          `  ${error}`,
      );
    }

    throw error;
  }

  if (configPath.endsWith(PACKAGE_JSON)) {
    // Event if there's no "jest" property in package.json we will still use
    // an empty object.
    configObject = configObject.jest || {};
  }

  if (typeof configObject === 'function') {
    configObject = await configObject();
  }

View on GitHub (pinned to f49721c78e)

Solutions

  1. Read the full wrapped error message - it lists both the native and loader failure reasons
  2. Reproduce in isolation by running `node --experimental-strip-types jest.config.ts` or `ts-node jest.config.ts` directly
  3. Install/verify the configured loader (ts-node or esbuild-register) if native compilation is insufficient
  4. Fix the TypeScript or import error indicated in the nested message

Example fix

// before: jest.config.ts imports a non-existent preset
import base from './nonexistent';
export default {...base};
// after
import base from './jest.base';
export default {...base};
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const config = await readConfigFileAndSetRootDir(configPath);
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Jest: Failed to parse the TypeScript config file')) {
    // inspect the inner cause: missing loader vs syntax error vs missing import
    console.error('TS config load failed:', e.message);
  }
  throw e;
}

Prevention

When it happens

Trigger: A jest.config.ts with a syntax error, an import of a missing module from the config, invalid TypeScript that neither native Node nor ts-node can compile, or a config using ESM syntax in a CJS context with no working loader.

Common situations: Broken imports in the config after a refactor; ts-node not installed but config uses TS-only features incompatible with native strip-types; type errors that break compilation under stricter loader settings.

Related errors


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