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

Misleading warning about import.meta #2723

Closed
timdp opened this issue Dec 7, 2022 · 2 comments
Closed

Misleading warning about import.meta #2723

timdp opened this issue Dec 7, 2022 · 2 comments

Comments

@timdp
Copy link

timdp commented Dec 7, 2022

The yargs package contains an ESM shim that checks for import.meta support using a try block:

https://github.com/yargs/yargs/blob/2e0ef3c965dd788ec4af0735ce96d66ed9f91cc0/lib/platform-shims/esm.mjs#L18-L23

As of esbuild v0.16.1, including yargs in a CommonJS bundle gives me this warning:

▲ [WARNING] "import.meta" is not available with the "cjs" output format and will be empty [empty-import-meta]

    ../../node_modules/yargs/lib/platform-shims/esm.mjs:20:28:
      20 │   __dirname = fileURLToPath(import.meta.url);
         ╵                             ~~~~~~~~~~~

  You need to set the output format to "esm" for "import.meta" to work correctly.

which is technically correct, but the whole point of the try block is, of course, to have a fallback for it. Maybe esbuild could detect that scenario (for simple cases)? Or, alternatively, provide guidance as to how to avoid it in yargs?

(In the meantime, I will work around it with a log override.)

@evanw evanw closed this as completed in a4d7d97 Dec 8, 2022
@houyaowei
Copy link

I got the same error

@AFoaad
Copy link

AFoaad commented Dec 2, 2023

did you solve it, and how?

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

3 participants