jestjs/jest · error · Error

● Invalid transformer module: "${slash(transformPath)}" sp

Error message

● Invalid transformer module:
  "${slash(transformPath)}" specified in the "transform" object of Jest configuration
  must export a `process` or `processAsync` or `createTransformer` function.

  Code Transformation Documentation:
  https://jestjs.io/docs/code-transformation

What it means

Thrown by `loadTransformers` (ScriptTransformer.ts:283-285) via `makeInvalidTransformerError` when a configured transformer module loads to `null`/`undefined`. The transform config entry resolved and required successfully, but the module exports nothing (no default, no named `process`/`processAsync`/`createTransformer`).

Source

Thrown at packages/jest-transform/src/ScriptTransformer.ts:284

  private _getTransformPath(filename: string) {
    const transformInfo = this._getTransformPatternAndPath(filename);
    if (!Array.isArray(transformInfo)) {
      return undefined;
    }

    return transformInfo[1];
  }

  async loadTransformers(): Promise<void> {
    await Promise.all(
      this._config.transform.map(
        async ([transformPattern, transformPath, transformerConfig], i) => {
          let transformer: Transformer | TransformerFactory<Transformer> =
            await requireOrImportModule(transformPath);

          if (transformer == null) {
            throw new Error(makeInvalidTransformerError(transformPath));
          }
          if (isTransformerFactory(transformer)) {
            transformer =
              await transformer.createTransformer(transformerConfig);
          }
          if (
            typeof transformer.process !== 'function' &&
            typeof transformer.processAsync !== 'function'
          ) {
            throw new TypeError(makeInvalidTransformerError(transformPath));
          }
          const res = {transformer, transformerConfig};
          const transformCacheKey = this._buildTransformCacheKey(
            this._cache.transformRegExp?.[i]?.[0].source ??
              new RegExp(transformPattern).source,
            transformPath,
          );
          this._transformCache.set(transformCacheKey, res);

View on GitHub (pinned to f49721c78e)

Solutions

  1. Open the resolved transformer module and confirm it exports one of: `process`, `processAsync`, or `createTransformer` (or a default object containing them).
  2. For CommonJS: ensure `module.exports = { process(...) {...} }` (or `module.exports = { createTransformer }`).
  3. Print the resolved path with `require.resolve('your-transformer')` and verify it points where you expect.
  4. Update the `transform` entry's second tuple element to the correct file.

Example fix

// before: my-transformer.js (exports nothing)
const { compile } = require('./compiler');
function process(src, filename) { return { code: compile(src) }; }
// after
const { compile } = require('./compiler');
module.exports = {
  process(src, filename) { return { code: compile(src) }; },
};
Defensive patterns

Strategy: type-guard

Validate before calling

const mod = require(transformPath);
if (mod == null) throw new Error('transformer module exports nothing');

Type guard

const hasTransformerExport = (m: any): boolean =>
  m != null && (typeof m.process === 'function' || typeof m.processAsync === 'function' || typeof m.createTransformer === 'function');

Prevention

When it happens

Trigger: A `transform` config entry points at a module whose `module.exports` / `export default` is null or absent - e.g. a module that only has side effects, a CommonJS module that forgot to assign `module.exports`, or an ESM module with only named exports when Jest needs a default.

Common situations: Mistyped transformer path resolving to an incidental index.js that exports nothing; transformer written as ESM with named exports but no default/factory; circular-import edge case causing the module object to be undefined at require time; transformer package that was tree-shaken or whose main field points at the wrong file.

Related errors


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