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
- Use one of the documented values: 'node' (default), 'electron', or 'user'.
- Omit `from` entirely to let Commander auto-detect node/electron/eval.
- 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
- Restrict `from` to the documented set; omit it for auto-detect when unsure.
- Drive the value from a typed const, not a free string.
- Pin Commander version to align with the supported `from` set.
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
- first parameter to parse must be array or undefined
- To add an Option object use addOption() instead of option()
- Can not call parse again when storeOptionsAsProperties is tr
- Not a number.
- Not a number.
AI-assisted analysis of tj/commander.js@ba6d13ddb4 (2026-08-03).
Data as JSON: /data/errors/7dd7fa19a37ee764.json.
Report an issue: GitHub.