Dodi’s assembly line: six modules become one bike. Step by step the bundler reads the imports from main.js, works out the run order, finds a cycle and an…
Why it matters
Most confusing build trouble (a file that never comes along, a build broken by one letter, undefined from another module) is a step of this walk. Knowing how a bundler reads and orders modules makes those errors readable.
The key idea
A bundler only knows what the entry reaches, and what is imported always runs first
Common mistakes
A new file never makes it into the bundle, without a single error A bundler only reaches what is imported (directly or not) from the entry. A file nothing imports is skipped silently: import it from a module already in.
A typo in a path: ./Lampu.js while the file is lampu.js, the build breaks A path that points at no file stops the build: [UNRESOLVED_IMPORT] Could not resolve. Capitals are sly: a Mac’s disk does not tell them apart, so the build works on a laptop and breaks on Linux CI. Write the path exactly as the file is named.
Two modules import each other, one of them gets undefined The module that runs first reads another’s value before it has run. In the browser that is a ReferenceError; in a Vite bundle (var) it is undefined, silently. Read the value inside a function (called later), or move what both use into a third module.
Try it in this playground
Run it to the end Watch the run numbers: leaves first, main.js last.
Find the orphan fileklakson.js is in the folder, but nothing imports it.
Stop the build with one letter Change the lamp’s import to ./lampuu.js.
Find a cycle Make busi.js import mesin.js, then run it.