-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Provide an option to transform dynamic import to Promise.resolve(() => require(...)) #1084
Comments
The data on MDN is incorrect. Just had to test the support level for that for a project at work last week and can confirm that node 12 does indeed support dynamic imports. Here is a simple repo to try that out locally https://github.com/marvinhagemeister/node-12-dynamic-import . Node versions can be easily switched locally via nvm or volta.
I recall there at the time being a huge discussion on twitter about the LTS version not supporting ESM and thereby blocking the transition away from CommonJS. The decision was made to backport ESM from newer release lines to So node cc @evanw |
The current environment version mechanism doesn't support a feature becoming unsupported and re-supported as the version number increases. So I'm planning to keep the supported version at node 13.2 for esbuild. Hopefully that's ok because node version 12 is no longer active anyway. |
Fair enough 👍 |
ESBuild fixes #1029 by always transform
import(...)
toPromise.resolve(() => require(...))
. However, this is not always desired.Old Node Versions
Dynamic import is not supported in earlier node version (<13).
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility.
Therefore, it should at least emit using Promise.resolve when having something like
--target=node12
.Static Site Generation
During static site generation, we might want to produce a single bundled js that contains all the async imported modules.
e.g. Suppose we have the following source
If dynamic import syntax is preserved, then webpack will create a chunk for both
a
andb
. However, this is not what we want for static site generation, since there is no concern for bundle size during build time, and we only want one single js for convenience.If the dynamic import syntax is transformed into
Promise.resolve(() => require(...))
, then we won't have the problem anymore.I encountered this problem when I am trying to adopt esbuild for docusaurus: facebook/docusaurus#4532
The text was updated successfully, but these errors were encountered: