jestjs/jest · error · Error

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

Error message

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

What it means

registerTsLoader accepts only 'ts-node' or 'esbuild-register' as the loader name from the @jest-config-loader docblock pragma. Any other string value reaches the final throw in the if/else chain, telling the user the loader name is not recognized.

Source

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

      );

      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 f49721c78e)

Solutions

  1. Use only 'ts-node' or 'esbuild-register' as the @jest-config-loader value
  2. Remove the pragma to fall back to the default 'ts-node'
  3. Fix typos such as 'tsnode' -> 'ts-node'

Example fix

/**
 * @jest-config-loader @swc-node/register
 */
// becomes
/**
 * @jest-config-loader esbuild-register
 */
Defensive patterns

Strategy: validation

Validate before calling

const VALID_LOADERS = new Set(['ts-node', 'esbuild-register']);
const loader = pragmas['jest-config-loader'];
if (typeof loader === 'string' && !VALID_LOADERS.has(loader)) {
  throw new Error(`Unsupported loader: ${loader}`);
}

Type guard

function isValidTsLoader(s: string): s is 'ts-node' | 'esbuild-register' {
  return s === 'ts-node' || s === 'esbuild-register';
}

Prevention

When it happens

Trigger: Setting `@jest-config-loader swc`, `@jest-config-loader @swc-node/register`, or a typo like `@jest-config-loader tsnode` in the config docblock.

Common situations: Typos in the loader name; assuming a loader Jest does not whitelist (e.g. swc, babel) is supported for config loading.

Related errors


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