tj/commander.js · error · Error

unexpected parse option { from: '${parseOptions.from}' }

Error message

unexpected parse option { from: '${parseOptions.from}' }

What it means

Thrown by Command._prepareUserArgs() at lib/command.js:1044-1048 when parseOptions.from is not one of the supported values ('node', 'electron', 'user', or undefined for auto). The switch has a default branch that rejects anything else, including case-typos like 'User' or invented modes like 'webpack'.

Source

Thrown at lib/command.js:1045

        userArgs = argv.slice(2);
        break;
      case 'electron':
        // @ts-ignore: because defaultApp is an unknown property
        if (process.defaultApp) {
          this._scriptPath = argv[1];
          userArgs = argv.slice(2);
        } else {
          userArgs = argv.slice(1);
        }
        break;
      case 'user':
        userArgs = argv.slice(0);
        break;
      case 'eval':
        userArgs = argv.slice(1);
        break;
      default:
        throw new Error(
          `unexpected parse option { from: '${parseOptions.from}' }`,
        );
    }

    // Find default name for program from arguments.
    if (!this._name && this._scriptPath)
      this.nameFromFilename(this._scriptPath);
    this._name = this._name || 'program';

    return userArgs;
  }

  /**
   * Parse `argv`, setting options and invoking commands when defined.
   *
   * Use parseAsync instead of parse if any of your action handlers are async.
   *
   * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!

View on GitHub (pinned to ba6d13ddb4)

Solutions

  1. Use one of the documented values: 'node' (default), 'electron', or 'user'.
  2. Omit `from` entirely to let Commander auto-detect node/electron/eval.
  3. Check the installed Commander version's docs for the supported set.

Example fix

// before (throws)
program.parse(argv, { from: 'User' });

// after
program.parse(argv, { from: 'user' });
Defensive patterns

Strategy: type-guard

Validate before calling

const FROM_VALUES = ['node', 'electron', 'user'];
function safeParse(cmd, argv, opts) {
  if (opts?.from && !FROM_VALUES.includes(opts.from)) {
    throw new TypeError(`parseOptions.from must be one of ${FROM_VALUES.join(', ')}`);
  }
  return cmd.parse(argv, opts);
}

Type guard

type ParseFrom = 'node' | 'electron' | 'user';
function isParseFrom(v: unknown): v is ParseFrom {
  return v === 'node' || v === 'electron' || v === 'user';
}

Prevention

When it happens

Trigger: `program.parse(argv, { from: 'browser' })`, `{ from: 'User' }` (wrong case), `{ from: 'node-modules' }`. The internal 'eval' mode exists but is not documented/public.

Common situations: Guessing a `from` value not in the docs; copy-paste from another CLI tool with different mode names; version skew where an older/newer Commander supported a different set.

Related errors


AI-assisted analysis of tj/commander.js@ba6d13ddb4 (2026-08-03). Data as JSON: /data/errors/7dd7fa19a37ee764.json. Report an issue: GitHub.