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

(dynamic import) transform should probably respect format: esm #1146

Closed
egoist opened this issue Apr 13, 2021 · 3 comments
Closed

(dynamic import) transform should probably respect format: esm #1146

egoist opened this issue Apr 13, 2021 · 3 comments

Comments

@egoist
Copy link

egoist commented Apr 13, 2021

When using with options { target: 'node12', format: 'esm' }, dynamic import is transformed to require:

> require('esbuild').transformSync(`import('foo')`,{target:'node12',format:'esm'})
{
  warnings: [],
  code: '...omitted...
    'Promise.resolve().then(() => __toModule(require("foo")));\n',
  map: ''
}

this would break rollup-plugin-esbuild since rollup only recognizes es module by default.

esbuild: 0.11.10

@evanw
Copy link
Owner

evanw commented Apr 15, 2021

Well dynamic import doesn't work in node 12, so this transformation is correct. Someone explicitly asked for this transformation to be added in #1084. Node 12 is no longer actively maintained and is now in maintenance mode. If you don't actually need to support node 12, the easiest solution here could just be to use target: 'node13.2' instead, which is the earliest version of node that supports this feature according to MDN.

Technically node shipped a back-ported version of node 12.x that does work with dynamic import, node 12.20+. So in theory this could be made to work by using target: 'node12.20' and then changing esbuild to mark node12.20 as supporting dynamic import. However, esbuild currently doesn't support a feature becoming unsupported and re-supported as the version number increases, so support for discontiguous version ranges would have to be added to esbuild first. See #1084 for more context.

@lukeed
Copy link
Contributor

lukeed commented Apr 15, 2021

It could be agreeable to pretend like all of Node 13.x didn't exist, though. For example, it included a different/incomplete "exports" resolution algorithm up until (and including) 13.7.

It's been a mess, tbh. Fun stuff.

@egoist
Copy link
Author

egoist commented Apr 17, 2021

👍 Sounds fair.

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