hexojs/hexo · error · TypeError

syntax highlighter is not registered

Error message

syntax highlighter ${name} is not registered

What it means

Thrown by SyntaxHighlight.exec when no highlighter is registered under the requested name. Unlike the other errors this is a runtime lookup failure: exec reads this.store[name] and, finding nothing, reports the engine as unregistered. The message is dynamic and includes the missing name.

Solutions

  1. Ensure the highlighter plugin that registers the requested name is installed and loaded.
  2. Align the config highlight.engine value with a name that was actually registered (check exact spelling/casing).
  3. Guard with query(name) before calling exec, falling back to a default highlighter or raw output.

Example fix

// before
hexo.extend.syntax_highlight.exec(engineName, opts);
// after
const fn = hexo.extend.syntax_highlight.query(engineName);
if (fn) hexo.extend.syntax_highlight.exec(engineName, opts);
else return raw; // or exec('default', opts)
Defensive patterns

Strategy: validation

Validate before calling

const fn = hexo.extend.syntax_highlight.query(name);
if (!fn) return raw; // or fall back to a registered default
hexo.extend.syntax_highlight.exec(name, options);

Type guard

const isRegistered = (name: string) => typeof hexo.extend.syntax_highlight.query(name) === 'function';

Try / catch

try {
  return hexo.extend.syntax_highlight.exec(name, options);
} catch (e) {
  if (e instanceof TypeError && /is not registered/.test(e.message)) return raw;
  throw e;
}

Prevention

When it happens

Trigger: Calling exec('prismjs', opts) when 'prismjs' was never registered, or requesting a name with a typo/different casing than what was registered.

Common situations: The highlight config references an engine ('highlight.js' vs 'hljs' vs 'prismjs') that the corresponding plugin did not register, or the highlight plugin is not installed/enabled while the config requests it.

Related errors


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

Appendix: source

Thrown at lib/extend/syntax_highlight.ts:55

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

  register(name: string, fn: StoreFunction): void {
    if (typeof fn !== 'function') throw new TypeError('fn must be a function');

    this.store[name] = fn;
  }

  query(name: string): StoreFunction {
    return name && this.store[name];
  }

  exec(name: string, options: HighlightExecArgs): string {
    const fn = this.store[name];

    if (!fn) throw new TypeError(`syntax highlighter ${name} is not registered`);
    const ctx = options.context;
    const args = options.args || [];

    return Reflect.apply(fn, ctx, args);
  }
}

export default SyntaxHighlight;

View on GitHub (pinned to 059cb17494)