hexojs/hexo · error · TypeError

name is required

Error message

name is required

What it means

Thrown by Console.register when the first 'name' argument is falsy. Hexo's console extend lets plugins register CLI sub-commands identified by name; every registration overloads start with a required name. This guard stops an anonymous or mis-named command from entering the store.

Source

Thrown at lib/extend/console.ts:76

  }

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

  /**
   * Register a console plugin
   * @param {String} name - The name of console plugin to be registered
   * @param {String} desc - More detailed information about a console command
   * @param {Option} options - The description of each option of a console command
   * @param {AnyFn} fn - The console plugin to be registered
   */
  register(name: string, fn: AnyFn): void
  register(name: string, desc: string, fn: AnyFn): void
  register(name: string, options: Option, fn: AnyFn): void
  register(name: string, desc: string, options: Option, fn: AnyFn): void
  register(name: string, desc: string | Option | AnyFn, options?: Option | AnyFn, fn?: AnyFn): void {
    if (!name) throw new TypeError('name is required');

    if (!fn) {
      if (options) {
        if (typeof options === 'function') {
          fn = options;

          if (typeof desc === 'object') { // name, options, fn
            options = desc;
            desc = '';
          } else { // name, desc, fn
            options = {};
          }
        } else {
          throw new TypeError('fn must be a function');
        }
      } else {
        // name, fn
        if (typeof desc === 'function') {

View on GitHub (pinned to 059cb17494)

Solutions

  1. Provide a non-empty name string as the first argument.
  2. If the name comes from configuration, validate it is a non-empty string before registering.
  3. Check the plugin's registration loop is not mapping over an undefined list producing empty names.

Example fix

// before
hexo.extend.console.register(cmdName || '', fn);
// after
if (cmdName) hexo.extend.console.register(cmdName, fn);
Defensive patterns

Strategy: validation

Validate before calling

if (!name || typeof name !== 'string') throw new Error('console command name required');
hexo.extend.console.register(name, fn);

Type guard

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

Prevention

When it happens

Trigger: Calling hexo.extend.console.register('', fn), register(undefined, fn), or register(null, 'desc', fn).

Common situations: A plugin reads a command name from a config/package field that is empty or missing, or a refactor dropped the name argument, leaving an empty string.

Related errors


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