hexojs/hexo · error · TypeError

entry is required

Error message

entry is required

What it means

Thrown by Injector.register when the 'entry' argument is falsy. The injector inserts content into page injection points (head_begin, head_end, body_begin, body_end); the entry selects where the value is injected.

Source

Thrown at lib/extend/injector.ts:50

    return this.store;
  }

  get(entry: Entry, to = 'default'): any[] {
    return Array.from(this.store[entry][to] || []);
  }

  getText(entry: Entry, to = 'default'): string {
    const arr = this.get(entry, to);
    if (!arr || !arr.length) return '';
    return arr.join('');
  }

  getSize(entry: Entry): number {
    return this.cache.apply(`${entry}-size`, () => Object.keys(this.store[entry]).length) as number;
  }

  register(entry: Entry, value: string | (() => string), to = 'default'): void {
    if (!entry) throw new TypeError('entry is required');
    if (typeof value === 'function') value = value();

    const entryMap = this.store[entry] || this.store.head_end;
    const valueSet = entryMap[to] || new Set();
    valueSet.add(value);
    entryMap[to] = valueSet;
  }

  _getPageType(pageLocals): string {
    let currentType = 'default';
    if (pageLocals.__index) currentType = 'home';
    if (pageLocals.__post) currentType = 'post';
    if (pageLocals.__page) currentType = 'page';
    if (pageLocals.archive) currentType = 'archive';
    if (pageLocals.category) currentType = 'category';
    if (pageLocals.tag) currentType = 'tag';
    if (pageLocals.layout) currentType = pageLocals.layout;

View on GitHub (pinned to 059cb17494)

Solutions

  1. Pass one of the valid Entry values (head_begin/head_end/body_begin/body_end) as the first argument.
  2. Default the entry to a valid point when it comes from dynamic logic.
  3. Guard against falsy entry before registering.

Example fix

// before
hexo.extend.injector.register(point, '<meta/>');
// after
hexo.extend.injector.register(point || 'head_end', '<meta/>');
Defensive patterns

Strategy: validation

Validate before calling

const ENTRIES = ['head_begin','head_end','body_begin','body_end'] as const;
if (!ENTRIES.includes(entry)) throw new Error('invalid injector entry');
hexo.extend.injector.register(entry, value);

Type guard

type Entry = 'head_begin'|'head_end'|'body_begin'|'body_end';
const isEntry = (e: unknown): e is Entry => typeof e === 'string' && ['head_begin','head_end','body_begin','body_end'].includes(e);

Prevention

When it happens

Trigger: Calling hexo.extend.injector.register('', '<style/>') or register(undefined, value).

Common situations: A theme/plugin computes the injection point from page metadata that is empty, or a typo leaves entry unset.

Related errors


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