hexojs/hexo · error · TypeError

fn must be a function

Error message

fn must be a function

What it means

Thrown by Processor.register when the resolved processor is not a function. Hexo's source processor supports (fn) and (pattern, fn); if the lone argument is not a function and no fn follows, registration fails.

Source

Thrown at lib/extend/processor.ts:38

  public store: Store;

  constructor() {
    this.store = [];
  }

  list(): Store {
    return this.store;
  }

  register(fn: StoreFunction): void;
  register(pattern: patternType, fn: StoreFunction): void;
  register(pattern: patternType | StoreFunction, fn?: StoreFunction): void {
    if (!fn) {
      if (typeof pattern === 'function') {
        fn = pattern;
        pattern = /(.*)/;
      } else {
        throw new TypeError('fn must be a function');
      }
    }

    if (fn.length > 1) {
      fn = Promise.promisify(fn);
    } else {
      fn = Promise.method(fn);
    }

    this.store.push({
      pattern: new Pattern(pattern as patternType),
      process: fn
    });
  }
}

export = Processor;

View on GitHub (pinned to 059cb17494)

Solutions

  1. Pass a function as the processor (register(fn)) or as the second argument (register(pattern, fn)).
  2. Verify imported processor symbols are defined.
  3. Do not pass a config object as the sole argument.

Example fix

// before
hexo.extend.processor.register(/\.md$/);
// after
hexo.extend.processor.register(/\.md$/, file => { /* ... */ });
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof fn !== 'function') throw new Error('processor must be a function');
hexo.extend.processor.register(pattern, fn);

Type guard

const isProcessorFn = (x: unknown): x is (...a: any[]) => any => typeof x === 'function';

Prevention

When it happens

Trigger: Calling register('/\.md$/') with no function, or register(pattern, null) where the second argument is not a function.

Common situations: A plugin passes a pattern object/string as the only argument and forgets the handler, or the imported handler is undefined.

Related errors


AI-assisted analysis of hexojs/hexo@059cb17494 (2026-08-12). Data as JSON: /api/errors/2ae273d95c1d1aa5. Report an issue: GitHub.