Bundler creates unused chunk
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
## Description
When bundling with splitting enabled, a chunk is created for every dynamic import even if it's not used.
## Expected behavior
Given the output `entry.js` is empty, there should be no chunks generated as they're not being referenced.
I added a `sideEffects: false` as well to indicate that `file-b.js` has no side effect.
When disabling splitting, it works expectedly (chunk is removed from being inlined in entry).
## Reproduction
https://esbuild.github.io/try/#YgAwLjE4LjE0AHsKICBidW5kbGU6IHRydWUsCiAgc3BsaXR0aW5nOiB0cnVlLAogIGZvcm1hdDogJ2VzbScsCiAgb3V0ZGlyOiAnLicsCn0AZQBlbnRyeS5qcwBleHBvcnQge30gZnJvbSAnLi9maWxlLWEuanMnAABmaWxlLWEuanMAZXhwb3J0IGNvbnN0IGEgPSAoKSA9PiBpbXBvcnQoJy4vZmlsZS1iLmpzJyk7AABmaWxlLWIuanMAZXhwb3J0IGNvbnN0IGIgPSAxOwAAcGFja2FnZS5qc29uAHsgInNpZGVFZmZlY3RzIjogZmFsc2UgfQ
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the linked case in the esbuild playground, using entry.js, file-a.js, file-b.js, and package.json, and inspect the generated entry and split chunks. Trace how dynamic imports and sideEffects: false affect splitting and tree shaking; done means the unused chunk is not generated while referenced chunks still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, 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