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

Executable subcommand not recognized after packaging with pkg #2289

Closed
TobiWo opened this issue Dec 4, 2024 · 4 comments
Closed

Executable subcommand not recognized after packaging with pkg #2289

TobiWo opened this issue Dec 4, 2024 · 4 comments

Comments

@TobiWo
Copy link

TobiWo commented Dec 4, 2024

Hi,

I'm writing this little tool. Everything works as expected with regards to subcommands etc. However, if I package the application with @yao-pkg/pkg I receive the following error while trying to execute a subcommand:

throw new Error(executableMissing);
        ^

Error: 'eth-validator-consolidate' does not exist
 - if 'consolidate' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
 - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
 - searched for local subcommand relative to directory '/snapshot/eth-validator/dist/cli'
    at ChildProcess.<anonymous> (/snapshot/eth-validator/node_modules/commander/lib/command.js:1225:15)
    at ChildProcess.emit (node:events:518:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)
    at onErrorNT (node:internal/child_process:483:16)
    at processTicksAndRejections (node:internal/process/task_queues:90:21)
    at process.runNextTicks [as _tickCallback] (node:internal/process/task_queues:69:3)
    at Function.runMain (pkg/prelude/bootstrap.js:1988:13)
    at node:internal/main/run_main_module:36:49

Since everything is working while just running it with the node binary I guess there is something going on during packaging. Maybe you have an alternative how to package commander based applications or you already know this issue? Any help is much appreciated.

Node version: 22.11.0

@shadowspawn
Copy link
Collaborator

A quick reply. There are two ways of using subcommands. Quoting from the README about commands:

There are two ways these can be implemented: using an action handler attached to the command, or as a stand-alone executable file (described in more detail later).

I suggest you use an action handler rather than a stand-alone executable which should avoid problems with pkg changing how the source files are arranged.

(I haven't tried using pkg myself yet, so this advice is in theory.)

@TobiWo
Copy link
Author

TobiWo commented Dec 5, 2024

Thank you for the quick reply. I will test it out and let you know whether it worked out.

@TobiWo
Copy link
Author

TobiWo commented Dec 6, 2024

@shadowspawn This worked indeed. Thanks a ton 🙏 .

@shadowspawn
Copy link
Collaborator

Thanks for update, glad you have it working.

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