evanw / evanw/esbuild

Suboptimal outputs where imports aren't dropped or inlined

Open
#4,229 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

a minimal input created from messing around trying to make something similar to my real case but extremely minimal, however can be fixed by running esbuild a second time
try

built (currently):

// chunk-AGCENTAR.js
/* this file is actually thing, not thing-T4WJ2JBY.js */
// entry.js
import"./chunk-AGCENTAR.js"; /* what's the point of this? chunk-AGCENTAR.js is an empty file */
// thing-T4WJ2JBY.js
import"./chunk-AGCENTAR.js"; /* why is this in the bundle?! it's not clear where the input came from or why it's in the bundle when it's unused */

built (ideal):

// entry.js
/* nothing */

closer to my actual case and can't be fixed by a rerun although slightly less minimal
try

built (currently):

// chunk-ASRF27SS.js
var e="useful";export{e as a};
// consumer-QQCKLKMJ.js
import{a as o}from"./chunk-ASRF27SS.js";console.log(o);
// entry.js
import"./chunk-ASRF27SS.js";import("./consumer-QQCKLKMJ.js");

built (ideal):

// entry.js
import("./consumer-ABCDEFGH.js");
// consumer-ABCDEFGH.js
console.log("useful");

why do you have such silly inputs in the first place?
i was working on bundling the sveltekit server. esbuild's build decided to add __export utility (minified to chunk-WOT6VMZA.js's a) and import it in places for reasons, but then it also went to add a useless (import"./chunk-WOT6VMZA.js") import to the entrypoint (see this). i tried to fix that by running esbuild a second time, but because of the issues outlined here it failed to remove the useless import.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the linked esbuild Try cases with bundling, splitting, minification, and tree shaking enabled, then compare the current and ideal outputs. Start by tracing how generated chunks and entry-point imports are retained or removed; done means unused imports and empty chunks are eliminated without breaking the dynamic import or useful value in the second case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.