bun
bun copied to clipboard
Commander Package does not work with Bun.
What version of Bun is running?
0.2.1 (canary)
What platform is your computer?
Darwin 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:25 PDT 2022; root:xnu-8020.140.41~1/RELEASE_X86_64 x86_64 i386
What steps can reproduce the bug?
- Create a new directory.
- Run
bun init - Run
bun add commander - Open
index.ts - Set contents to the example from the commander github
This example has been change to the ESM
importsyntax. I get the same result with both.
import { program } from 'commander';
program.option('--first').option('-s, --separator <char>');
program.parse();
const options = program.opts();
const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));
- Run
bun index.ts
How often does it reproduce? Is there a required condition?
Every time. There seems to be no required condition.
What is the expected behavior?
The program executes without error.
What do you see instead?
error: Cannot find package "child_process" from "/Users/elirichardson/bun/node_modules/commander/lib/command.js"

Additional information
No response
Confirmed on Ubuntu in virtual machine:
Linux 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64
This should be resolved once we support child_process, #595
@robobun
import { program } from 'commander';
program.option('--first').option('-s, --separator <char>');
program.parse();
const options = program.opts();
const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));
@Electroid here you go!
2 | program.option("--first").option("-s, --separator <char>");
3 | program.parse();
3 | const options = program.opts();
4 | const limit = options.first ? 1 : undefined;
5 |
6 | console.log(program.args[0].split(options.separator, limit));
^
TypeError: undefined is not an object (evaluating 'program.args[0].split')
at /tmp/bun-vHJi59/index.js:9:12
Code
import { program } from 'commander';
program.option('--first').option('-s, --separator <char>');
program.parse();
const options = program.opts();
const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));
Ran using the latest build of Bun, an all-in-one JavaScript runtime.
@robobun
const { program } = require('commander');
program
.option('--first')
.option('-s, --separator <char>');
program.parse();
const options = program.opts();
console.log("Options:", options);
console.log("Program:", program);
@Electroid here you go!
CommanderError: [Function: CommanderError],
Help: [Function: Help],
InvalidArgumentError: [Function: InvalidArgumentError],
InvalidOptionArgumentError: [Function: InvalidArgumentError],
Option: [Function: Option],
[Symbol(CommonJSTransformed)]: true,
copyInheritedSettings: [Function: copyInheritedSettings],
command: [Function: command],
createCommand: [Function: createCommand],
createHelp: [Function: createHelp],
configureHelp: [Function: configureHelp],
configureOutput: [Function: configureOutput],
showHelpAfterError: [Function: showHelpAfterError],
showSuggestionAfterError: [Function: showSuggestionAfterError],
addCommand: [Function: addCommand],
createArgument: [Function: createArgument],
argument: [Function: argument],
arguments: [Function: arguments],
addArgument: [Function: addArgument],
addHelpCommand: [Function: addHelpCommand],
_hasImplicitHelpCommand: [Function: _hasImplicitHelpCommand],
hook: [Function: hook],
exitOverride: [Function: exitOverride],
_exit: [Function: _exit],
action: [Function: action],
createOption: [Function: createOption],
addOption: [Function: addOption],
_optionEx: [Function: _optionEx],
option: [Function: option],
requiredOption: [Function: requiredOption],
combineFlagAndOptionalValue: [Function: combineFlagAndOptionalValue],
allowUnknownOption: [Function: allowUnknownOption],
allowExcessArguments: [Function: allowExcessArguments],
enablePositionalOptions: [Function: enablePositionalOptions],
passThroughOptions: [Function: passThroughOptions],
storeOptionsAsProperties: [Function: storeOptionsAsProperties],
getOptionValue: [Function: getOptionValue],
setOptionValue: [Function: setOptionValue],
setOptionValueWithSource: [Function: setOptionValueWithSource],
getOptionValueSource: [Function: getOptionValueSource],
_prepareUserArgs: [Function: _prepareUserArgs],
parse: [Function: parse],
parseAsync: [Function: parseAsync],
_executeSubCommand: [Function: _executeSubCommand],
_dispatchSubcommand: [Function: _dispatchSubcommand],
_checkNumberOfArguments: [Function: _checkNumberOfArguments],
_processArguments: [Function: _processArguments],
_chainOrCall: [Function: _chainOrCall],
_chainOrCallHooks: [Function: _chainOrCallHooks],
_chainOrCallSubCommandHook: [Function: _chainOrCallSubCommandHook],
_parseCommand: [Function: _parseCommand],
_findCommand: [Function: _findCommand],
_findOption: [Function: _findOption],
_checkForMissingMandatoryOptions: [Function: _checkForMissingMandatoryOptions],
_checkForConflictingLocalOptions: [Function: _checkForConflictingLocalOptions],
_checkForConflictingOptions: [Function: _checkForConflictingOptions],
parseOptions: [Function: parseOptions],
opts: [Function: opts],
optsWithGlobals: [Function: optsWithGlobals],
error: [Function: error],
_parseOptionsEnv: [Function: _parseOptionsEnv],
_parseOptionsImplied: [Function: _parseOptionsImplied],
missingArgument: [Function: missingArgument],
optionMissingArgument: [Function: optionMissingArgument],
missingMandatoryOptionValue: [Function: missingMandatoryOptionValue],
_conflictingOption: [Function: _conflictingOption],
unknownOption: [Function: unknownOption],
_excessArguments: [Function: _excessArguments],
unknownCommand: [Function: unknownCommand],
version: [Function: version],
description: [Function: description],
summary: [Function: summary],
alias: [Function: alias],
aliases: [Function: aliases],
usage: [Function: usage],
nameFromFilename: [Function: nameFromFilename],
executableDir: [Function: executableDir],
helpInformation: [Function: helpInformation],
_getHelpContext: [Function: _getHelpContext],
outputHelp: [Function: outputHelp],
helpOption: [Function: helpOption],
help: [Function: help],
addHelpText: [Function: addHelpText],
addListener: [Function: addListener],
on: [Function: on],
once: [Function: once],
prepend: [Function: prepend],
prependOnce: [Function: prependOnce],
removeListener: [Function: removeListener],
off: [Function: off],
removeAllListeners: [Function: removeAllListeners],
emit: [Function: emit],
eventNames: [Function: eventNames],
listenerCount: [Function: listenerCount],
listeners: [Function: listeners],
rawListeners: [Function: rawListeners],
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners]
}
Code
const { program } = require('commander');
program
.option('--first')
.option('-s, --separator <char>');
program.parse();
const options = program.opts();
console.log("Options:", options);
console.log("Program:", program);
Ran using the latest build of Bun, an all-in-one JavaScript runtime.
It looks like commander should work as of Bun v0.3.0 🎉
If you're still having issue, please feel free to open another issue.
@Electroid here you go!
1 | commander;
Refe
ReferenceError: Can't find variable: commander
at /tmp/bun-IABuhM/index.tsx:1:0
Code
commander
Ran using the latest build of Bun, an all-in-one JavaScript runtime.