evanw / evanw/esbuild

Entry point modules not being re-used, chunks generated unnecessarily?

Open
#2,299 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

[Here's a quick scenario](https://hyrious.me/esbuild-repl/?version=0.14.42&mode=build&modules=%5B%5B%22button.js%22%2C%22export+function+Button%28%29+%7B%5Cn%5Ctreturn+%5C%22button%5C%22%3B%5Cn%7D%22%2C1%5D%2C%5B%22main.js%22%2C%22import+%7B+Button+%7D+from+%5C%22.%2Fbutton.js%5C%22%3B%5Cnexport+default+function+App%28%29+%7B%5Cn%5Ctreturn+Button%28%29%3B%5Cn%7D%22%2C1%5D%5D&buildOptions=%7B%22bundle%22%3Atrue%2C%22format%22%3A%22esm%22%2C%22splitting%22%3Atrue%7D)

Where I have _two_ entrypoints, `button.js` and `main.js`. `main.js` imports from `button.js`. I would've expected two output modules -- one for button, one for main, with main importing from button. Instead, esbuild builds an extra chunk that both main.js and button.js import from.

Why is this extra chunk necessary, instead of main.js reusing the button.js entrypoint module?

Thanks!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked esbuild REPL scenario using button.js and main.js, with bundle, esm format, and splitting enabled. Inspect the generated entry modules and shared chunk to understand the reported behavior. Done means documenting whether the extra chunk is expected or identifying a concrete change needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.