jestjs/jest · error · Error

Jest: ' ' is not a valid TypeScript configuration loader.

Error message

Jest: '${loader}' is not a valid TypeScript configuration loader.

What it means

Thrown by registerTsLoader when the loader name from the @jest-config-loader pragma is neither 'ts-node' nor 'esbuild-register'. The TsLoaderModule type is a closed union, so any other value falls through both branches and reaches this terminal throw.

Solutions

  1. Use exactly 'ts-node' or 'esbuild-register' as the @jest-config-loader value
  2. Install the chosen loader as a devDependency
  3. If you need a different loader, fall back to native Node TS support (Node 22.18+/23.6+) instead of the pragma

Example fix

/**
 * @jest-config-loader tsx
 */
// before: invalid -> error

/**
 * @jest-config-loader esbuild-register
 */
// after: valid loader
Defensive patterns

Strategy: validation

Validate before calling

import { extract, parse } from 'jest-docblock';
import * as fs from 'node:fs';
const VALID_LOADERS = ['ts-node', 'esbuild-register'] as const;
const pragmas = parse(extract(fs.readFileSync('jest.config.ts', 'utf8')));
const loader = pragmas['jest-config-loader'];
if (typeof loader === 'string' && !VALID_LOADERS.includes(loader as any)) {
  throw new Error(`Unsupported loader: ${loader}. Use one of ${VALID_LOADERS.join(', ')}`);
}

Type guard

type TsLoaderName = 'ts-node' | 'esbuild-register';
function isTsLoaderName(value: unknown): value is TsLoaderName {
  return value === 'ts-node' || value === 'esbuild-register';
}

Prevention

When it happens

Trigger: Typing the pragma value incorrectly (e.g. 'tsx', 'swc', '@swc/register', 'ts-node/register'), using a trailing path, or misspelling 'ts-node'/'esbuild-register'.

Common situations: Developers wanting to use a newer TS loader (tsx, swc) that Jest does not yet accept; copy-paste typos; assuming the pragma accepts the same names as --require flags.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/cab537ff26c05536. Report an issue: GitHub.

Appendix: source

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

      );

      let instance: {unregister: () => void} | undefined;

      return {
        enabled: (bool: boolean) => {
          if (bool) {
            instance = tsLoader.register({
              target: `node${process.version.slice(1)}`,
              ...extraTSLoaderOptions,
            });
          } else {
            instance?.unregister();
          }
        },
      };
    }

    throw new Error(
      `Jest: '${loader}' is not a valid TypeScript configuration loader.`,
    );
  } catch (error) {
    if (
      isError(error) &&
      (error as NodeJS.ErrnoException).code === 'ERR_MODULE_NOT_FOUND'
    ) {
      throw new Error(
        `Jest: '${loader}' is required for the TypeScript configuration files. Make sure it is installed\nError: ${error.message}`,
        {cause: error},
      );
    }

    throw error;
  }
}

View on GitHub (pinned to 8e6d128e4a)