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

Default version command does not work for esmodule packages #165

Open
JakeStanger opened this issue Jun 4, 2022 · 0 comments
Open

Default version command does not work for esmodule packages #165

JakeStanger opened this issue Jun 4, 2022 · 0 comments

Comments

@JakeStanger
Copy link

If you use the now stable esmodule resolution (by including "type": "module" in your package.json), the default version command throws an error trying to get the main module.

λ fe version
/home/jake/Programming/filebrowser2/node_modules/args/lib/version.js:26
  const pkg = findPackage(path.dirname(process.mainModule.filename))
                                                          ^

TypeError: Cannot read properties of undefined (reading 'filename')
    at module.exports [as showVersion] (/home/jake/Programming/filebrowser2/node_modules/args/lib/version.js:26:59)
    at Args.runCommand (/home/jake/Programming/filebrowser2/node_modules/args/lib/utils.js:306:37)
    at module.exports [as parse] (/home/jake/Programming/filebrowser2/node_modules/args/lib/parse.js:63:10)
    at file:///home/jake/Programming/filebrowser2/lib/cli.js:9:20
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async loadESM (node:internal/process/esm_loader:85:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Node.js v18.3.0

I don't think there's going to be a very nice way around this unfortunately, as the concept of a "main" module is kinda thrown out the window. You can use meta.import.url to get the current module's URL, and could possibly do a walk up the filetree, but I'm not sure how reliable that'll be.

If the command can't be easily fixed, I propose args does a check to see if process.mainModule is defined, and if not just disables the version command.

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

1 participant