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

remove dynamic import statements #231

Closed
raphaelschwinger opened this issue Mar 10, 2021 · 6 comments
Closed

remove dynamic import statements #231

raphaelschwinger opened this issue Mar 10, 2021 · 6 comments

Comments

@raphaelschwinger
Copy link
Contributor

Thanks @simov and others for your great work!

Summary

Importing from paths generated at runtime breaks
parcel, see (parcel-bundler/parcel#4031),
or esbuild, see (evanw/esbuild#480).
Building fails or throws a warning like this:

warning: This call to "require" will not be bundled because the argument is not a string literal (surround with a try/catch to silence this warning)
    32 │   var handler = require(`./lib/handler/koa-${version}`)

This can lead to problems at runtime.

@simov
Copy link
Owner

simov commented Mar 11, 2021

Hi, I understand that your PR fixes the string literal issue, but does it really solves the issue of not having some of those optional files?

@raphaelschwinger
Copy link
Contributor Author

Hey @simov, What do you mean with "having some of those optional files"? Require should only be executed for a specific file if the same conditions as before apply.

@simov
Copy link
Owner

simov commented Mar 11, 2021

How is parcel or esbuild bundling anything in case they are not trying to resolve all paths eagerly by static analysis? That's how webpack works, it tries to bundle all paths found regardless of logical code structure. So what happens is that webpack throws errors #212 for the files that are missing.

@raphaelschwinger
Copy link
Contributor Author

As far as I understand it esbuild is only bundling stuff it can find by static analysis. Thats why all of those require statements in grant.js get not executed and then it fails at runtime.

@simov
Copy link
Owner

simov commented Mar 20, 2021

I did a few tests on my own, fixed in #232

@simov simov closed this as completed Mar 20, 2021
@raphaelschwinger
Copy link
Contributor Author

@simov thank you :)

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