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

Version 7.x.x/8.x.x fails to parse fields of type path #1545

Closed
ishanjain28 opened this issue Jun 8, 2021 · 5 comments
Closed

Version 7.x.x/8.x.x fails to parse fields of type path #1545

ishanjain28 opened this issue Jun 8, 2021 · 5 comments

Comments

@ishanjain28
Copy link

Here is the code,

import { program } from "commander";

program
  .version("0.0.0")
  .requiredOption(
    "-i, --input <path>",
    "input JSON file location containing a claims tree"
  );

I call the program like,

node .\submit-to-kv-store.mjs -i .\package.json 

With commander version ^7.0.0 OR ^8.0.0, This fails with the error down below. ^6.0.0 works fine.

Error log,

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
    at Object.openSync (fs.js:468:10)
    at Object.readFileSync (fs.js:377:35)
    at file:///C:/Users/emerald/projects/submit-to-kv-store.mjs:23:28
    at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
    at async Loader.import (internal/modules/esm/loader.js:166:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}
@ishanjain28 ishanjain28 changed the title Version 7.x.x fails to parse fields of type path Version 7.x.x/8.x.x fails to parse fields of type path Jun 8, 2021
@shadowspawn
Copy link
Collaborator

I have not managed to reproduce on Mac. What version of node are you using?

I suspect the error is coming from the import line itself rather than the rest of the code.

Commander v7.1.0 added a wrapper for esm to support named imports (see #1440). The new syntax is:

import { program } from 'commander/esm.mjs';

@ishanjain28
Copy link
Author

I am on Node 14.17.

I'll try the suggested fix, Thank you

@ishanjain28
Copy link
Author

After applying the suggested fix, I still get the same error.

I also tried,

import { Command } from "commander/esm.mjs";
const program = new Command();

but I still get the same error.

I am testing this with Node 14.xx on Linux and Windows.

@shadowspawn
Copy link
Collaborator

Are you running more code in your failing case than in the example code you gave, and trying to read the file using program.input?

The way options are stored by default has changed between Commander v6 and v7. The code that will work with default behaviour in both is program.opts().input.

See e.g. #1441

@ishanjain28
Copy link
Author

This was the problem! I inherited this old code, somehow commander version was updated to 7.x.x from 6.x.x and I didn't notice. I was still reading arguments like, program.input instead of program.opts().input`.

Thank you so much for your time and helping me with this.

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