Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding --no-emit option results in error #1237

Closed
jonhue opened this issue Apr 2, 2020 · 3 comments
Closed

Adding --no-emit option results in error #1237

jonhue opened this issue Apr 2, 2020 · 3 comments

Comments

@jonhue
Copy link

jonhue commented Apr 2, 2020

Adding the option .option('--no-emit', 'description') to a command results in the following error when running bin cmd -h:

/mnt/c/code/tony-lang/cli/node_modules/commander/index.js:1495
    this.emit(this._helpLongFlag);
         ^

TypeError: this.emit is not a function
    at Command.outputHelp (/mnt/c/code/tony-lang/cli/node_modules/commander/index.js:1495:10)
    at outputHelpIfRequested (/mnt/c/code/tony-lang/cli/node_modules/commander/index.js:1645:9)
    at Command._parseCommand (/mnt/c/code/tony-lang/cli/node_modules/commander/index.js:893:7)
    at Command._dispatchSubcommand (/mnt/c/code/tony-lang/cli/node_modules/commander/index.js:860:18)
    at Command._parseCommand (/mnt/c/code/tony-lang/cli/node_modules/commander/index.js:877:12)
    at Command.parse (/mnt/c/code/tony-lang/cli/node_modules/commander/index.js:712:10)
    at Object.<anonymous> (/mnt/c/code/tony-lang/cli/dist/index.js:26:20)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)

Is this expected?

@shadowspawn
Copy link
Collaborator

The problem is due to a clash of your option name with the properties of the Command object, in this case the emit method from EventListener. The value for the --no-emit flag is stored as the emit property and overwrites the expected method.

To resolve the problem, you may opt-in to a new way of storing the option values using .storeOptionsAsProperties(false) which was added specifically to avoid this sort of problem.

See https://github.com/tj/commander.js#avoiding-option-name-clashes

@jonhue
Copy link
Author

jonhue commented Apr 2, 2020

Thanks, that makes sense! 🙂

@shadowspawn
Copy link
Collaborator

Opened a PR to add a warning for option name clashes: #1275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants