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

Incorrect evaluation order with code splitting and dynamic imports #1679

Closed
amireh opened this issue Oct 13, 2021 · 2 comments
Closed

Incorrect evaluation order with code splitting and dynamic imports #1679

amireh opened this issue Oct 13, 2021 · 2 comments

Comments

@amireh
Copy link

amireh commented Oct 13, 2021

Consider the following code:

// index.js
import './a.js'
import './b.js'
import('./b.js')

// a.js
import './core-module.js'

// b.js
import './core-module.js'

I would expect core-module to be evaluated first, then a and then b, but in fact it appears that b is being evaluated before a. This is contrary to what other environments produce:

esbuild-splitting-test$ ./test.sh 
node:
[ 'core', 'a', 'b' ]
webpack:
[ 'core', 'a', 'b' ]
rollup:
[ 'core', 'a', 'b' ]
esbuild:
[ 'core', 'b', 'a' ]

Please see this repository to reproduce: https://github.com/amireh/esbuild-splitting-test. The example index.js in this reduced form may look silly, but it does represent the case I'm facing in a large codebase where an entrypoint dynamically imports another file c that then imports b and causes incomprehensible issues.

This might be related to #399 only that this doesn't have to do with multiple entry points (or does it?)

Thank you for your terrific work.

@evanw
Copy link
Owner

evanw commented Oct 14, 2021

Yes, I believe this is another instance of #399. When code splitting is active, dynamic import() creates another entry point for the imported file which is why the output file contains both index.js and b-[hash].js.

@amireh
Copy link
Author

amireh commented Oct 14, 2021

Ok that makes sense. I will close this one in favor of #399 then, thank you for clarifying.

Did I understand correctly from that thread that you are in the middle of addressing this, or are you open for a contribution? I'm willing to try as this is the last step for us to take esbuild to production.

@amireh amireh closed this as completed Oct 15, 2021
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