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

Warnings for use of require.cache #812

Closed
huonw opened this issue Feb 15, 2021 · 2 comments · Fixed by #813
Closed

Warnings for use of require.cache #812

huonw opened this issue Feb 15, 2021 · 2 comments · Fixed by #813

Comments

@huonw
Copy link
Contributor

huonw commented Feb 15, 2021

Hi, thanks for esbuild!

We've been using it with an Amazon CDK project, and noticed that we get a bunch of warnings about the require.cache property from the following file (or at least, the compiled JS version):

https://github.com/aws/aws-cdk/blob/c0944d2fcd4351997b8b8e981f88cf3145e065b4/packages/%40aws-cdk/core/lib/private/runtime-info.ts

 > ../node_modules/@aws-cdk/aws-lambda/node_modules/@aws-cdk/core/lib/private/runtime-info.js: warning: Indirect calls to "require" will not be bundled (surround with a try/catch to silence this warning)
    15 │     for (const fileName of Object.keys(require.cache)) {
       ╵                                        ~~~~~~~

 > ../node_modules/@aws-cdk/aws-lambda/node_modules/@aws-cdk/core/lib/private/runtime-info.js: warning: Indirect calls to "require" will not be bundled (surround with a try/catch to silence this warning)
    64 │     const mod = require.cache[fileName];
       ╵                 ~~~~~~~

...

AIUI, these are explicitly not designed to be affecting bundling, are are just for introspecting the current set of packages. As such, they should be okay and not warned about, similar to require.main in #560.

(Fair warning: I don't understand all the moving parts here, so this could easily be a valid warning that needs to be fixed/addressed/managed upstream.)

@evanw
Copy link
Owner

evanw commented Feb 16, 2021

Thanks for pointing this out. This warning was intended to catch cases where people store require in a variable and then call it later, since esbuild doesn't track the identity of the function through indirect references. But any property access expression like this is probably fine to ignore and not warn about since it's probably just some other API that isn't going to end up calling require. So I'd like to fix this by just removing warnings for all property accesses off of require instead. I can make that change.

@huonw
Copy link
Contributor Author

huonw commented Feb 16, 2021

Ah, that's an even better fix. Thanks for adding it to #813 and merging so quickly!

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

Successfully merging a pull request may close this issue.

2 participants