hexojs/hexo · error · TypeError

type is required

Error message

type is required

What it means

Thrown by Filter.unregister when the 'type' argument is falsy. Unregistration needs the filter type (e.g. 'after_post_render') to locate the correct list; an empty type has nothing to match against.

Source

Thrown at lib/extend/filter.ts:65

      }
    }

    if (typeof fn !== 'function') throw new TypeError('fn must be a function');

    type = typeAlias[type as string] || type;
    priority = priority == null ? 10 : priority;

    const store = this.store[type as string] || [];
    this.store[type as string] = store;

    fn.priority = priority;
    store.push(fn);

    store.sort((a, b) => a.priority - b.priority);
  }

  unregister(type: string, fn: StoreFunction): void {
    if (!type) throw new TypeError('type is required');
    if (typeof fn !== 'function') throw new TypeError('fn must be a function');

    type = typeAlias[type] || type;

    const list = this.list(type);
    if (!list || !list.length) return;

    const index = list.indexOf(fn);

    if (index !== -1) list.splice(index, 1);
  }

  exec(type: string, data: any, options: FilterOptions = {}): Promise<any> {
    const filters = this.list(type);
    if (filters.length === 0) return Promise.resolve(data);

    const ctx = options.context;
    const args = options.args || [];

View on GitHub (pinned to 059cb17494)

Solutions

  1. Pass a non-empty filter type string.
  2. Guard with a truthiness check before calling unregister.
  3. Confirm the type matches an alias used at registration time.

Example fix

// before
hexo.extend.filter.unregister(typeVar, fn);
// after
if (typeVar) hexo.extend.filter.unregister(typeVar, fn);
Defensive patterns

Strategy: validation

Validate before calling

if (!type) throw new Error('filter type required');
hexo.extend.filter.unregister(type, fn);

Type guard

const isValidType = (t: unknown): t is string => typeof t === 'string' && t.length > 0;

Prevention

When it happens

Trigger: Calling hexo.extend.filter.unregister('', fn) or unregister(undefined, fn).

Common situations: A plugin's teardown path passes a type variable that was never set, or iterates a list producing empty types.

Related errors


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