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

Is it possible to suppress a warning via a comment? #512

Closed
LeeCheneler opened this issue Nov 8, 2020 · 4 comments
Closed

Is it possible to suppress a warning via a comment? #512

LeeCheneler opened this issue Nov 8, 2020 · 4 comments

Comments

@LeeCheneler
Copy link

I'm getting this warning currently:

warning: This call to "require" will not be bundled because the argument is not a string literal

It's totally legitimate and is a useful warning, however its fine in this instance:

if (jestConfigExists) {
  try {
    jestConfig = require(jestConfigFilename);
  } catch (error) {
    console.error("Failed to load jest.config.js ->", error?.message ?? "");
    return process.exit(1);
  }
}

It would be nice to be able to disable the warning with an explanation like:

if (jestConfigExists) {
  try {
    // esbuild-disable-warning require-not-bundled - dynamic require is expected and safe here
    jestConfig = require(jestConfigFilename);
  } catch (error) {
    console.error("Failed to load jest.config.js ->", error.message);
    return process.exit(1);
  }
}
@evanw
Copy link
Owner

evanw commented Nov 11, 2020

The escape hatch for this is currently to surround the require() call with a try/catch statement. However, it looks like it's not applying in this case. That's an oversight, sorry. Will fix.

@evanw evanw closed this as completed in 53ba035 Nov 11, 2020
@rw3iss
Copy link

rw3iss commented Feb 9, 2021

Hi @evanw, What do you suggest we do if an imported module is using require() (within itself), and we want to suppress the warning?

@evanw
Copy link
Owner

evanw commented Feb 9, 2021

Some options:

  1. Disable warnings with --log-level=warning
  2. Use esbuild's API instead of the CLI, disable all logging with logLevel: 'silent', and print the data from the .errors and .warnings properties on the result yourself after filtering them

@rw3iss
Copy link

rw3iss commented Feb 9, 2021

Thanks! Am using the API :-)

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