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

esbuild prints warning on usage of require.main #560

Closed
vladmandic opened this issue Nov 25, 2020 · 1 comment
Closed

esbuild prints warning on usage of require.main #560

vladmandic opened this issue Nov 25, 2020 · 1 comment

Comments

@vladmandic
Copy link

vladmandic commented Nov 25, 2020

nodejs v15 deprecated usage of module.parent to detect if module is loaded or running as standalone:
[DEP0144] DeprecationWarning: module.parent is deprecated due to accuracy issues. Please use require.main to find program entry point instead.

however, esbuild throws warning when using require.main:
warning: Indirect calls to "require" will not be bundled (surround with a try/catch to silence this warning)
178 │ if (require.main === module) test();

like the suggestion says, placing try/catch block around it works, but that is anything but elegant.

@evanw
Copy link
Owner

evanw commented Nov 25, 2020

Thanks for pointing this out. This is a common pattern so you're right, esbuild should deal with this. I think it should be sufficient to skip warning about require.main if the output format is CommonJS. With other output formats, require may be undefined so it still seems appropriate to warn (and to wrap with try/catch).

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