Tooling and buildThe build pipelinePart 3
sideEffects false Saved 224 Bytes and Broke the Program
A bundler drops a module when it can prove nothing observable happens without it. The sideEffects field replaces that proof with your word, and here is what that cost.

The same source, bundled twice. The only difference is one line in a
dependency’s package.json:
$ node build.mjs # rolldown 1.2.7
--- modules retained ---
node_modules/toolkit/src/format.js
node_modules/toolkit/src/index.js
node_modules/toolkit/src/polyfill.js
src/main.js
--- bytes: 477 ---$ node build.mjs # after adding "sideEffects": false
--- modules retained ---
node_modules/toolkit/src/format.js
src/main.js
--- bytes: 253 ---Two hundred and twenty-four bytes smaller. Running it:
TypeError: [1,2,3].last is not a functionWhat the bundler was doing before you helped
Tree shaking is usually described as “removing unused code”, which is the result rather than the method. The method is two separate questions, and the package above answers them differently.
The first is reachability. main.js imports formatDate and never mentions
deepClone, so nothing reads the binding clone.js exports, and clone.js is
gone from the first build’s module list. That part is a graph walk and it needs
no permission from anyone.
The second is whether the module can be skipped, which is a different claim.
polyfill.js exports nothing. Nobody imports a binding from it. It is reachable
only through a bare import './polyfill.js' in the package index, and its entire
purpose is what happens when it is evaluated:
if (!Array.prototype.last) {
Object.defineProperty(Array.prototype, 'last', { value() { … } });
}The bundler kept it because it could not prove otherwise, and that is the whole mechanism: a module is dropped only when nothing observable happens if it is absent. A top-level assignment to a shared object is observable, so the proof fails and the module stays.
The rule cuts the other way too, which is worth seeing before deciding the
bundler is timid. Put a console.log at the top of clone.js — the module whose
export nobody uses — and it comes back into the bundle:
node_modules/toolkit/src/clone.js
node_modules/toolkit/src/format.js
node_modules/toolkit/src/index.js
node_modules/toolkit/src/polyfill.js
--- bytes: 569 ---Unused export, retained module. Reachability said the binding was dead; evaluation said the module was not.
The field is an assertion, not a hint
"sideEffects": false does not describe your code to the bundler. It tells the
bundler to stop asking. The claim it makes is specific: evaluating any module in
this package produces nothing observable, so any module whose bindings are unused
may be skipped entirely.
For a package of pure functions the claim is true, and the received wisdom is
that stating it is what rescues a re-export barrel. That turns out to need
checking, and a later section does check it. For the package above the claim is
false, and nothing in the toolchain can tell. The build succeeded. The bundle
shrank. The crash arrives at runtime, on whichever page first calls .last(),
in code that is not the code that made the promise.
That asymmetry is what makes this different from most build configuration. A
wrong target, a wrong format, a wrong external — those fail loudly at build
time. This one produces a smaller artifact and a working build log.
Listing the file is not enough
The documented escape hatch is the array form: name the modules that do have effects. The obvious attempt does not work:
"sideEffects": ["./src/polyfill.js"]node_modules/toolkit/src/format.js
--- bytes: 253 --- -> TypeError: [1,2,3].last is not a functionIdentical to the false case. The reason is one step up the graph. index.js is
not in the list, so index.js is effect-free, so index.js may be skipped —
and the import './polyfill.js' statement lives inside index.js. Skipping the
importer removes the only path to the module you were trying to protect.
Every module on the import path has to be named:
"sideEffects": ["./src/polyfill.js", "./src/index.js"]node_modules/toolkit/src/format.js
node_modules/toolkit/src/index.js
node_modules/toolkit/src/polyfill.js
--- bytes: 477 --- -> runsBoth bytes and behavior are back. The leading ./ is optional —
["src/polyfill.js", "src/index.js"] behaved identically — but a glob that
matches only the leaf, ["**/polyfill.js"], crashed exactly like the single-file
version, for the same reason.
And on a package where the promise is true?
The argument for the flag is that a barrel of re-exports defeats the analysis, so the author has to help. That is worth checking rather than assuming. A second package: eight pure modules, an index that re-exports all eight, one of them imported.
--- pure package, sideEffects: no field
node_modules/pure/src/a.js
--- bytes: 158 ---
--- pure package, sideEffects: false
node_modules/pure/src/a.js
--- bytes: 158 ---Identical. Rolldown had already proved the other seven modules were skippable, and the assertion added nothing to a conclusion it had reached on its own. Seven of eight dropped either way.
So on this shape the field has an upside of zero bytes and a downside of a
runtime TypeError. That is not a general law — a package shipping CommonJS, or
one whose modules do more at the top level than declare functions, will give the
analysis more trouble and the flag more to do. It is a reason to measure before
adding it rather than adding it because a checklist said to.
What to do with this
If you publish a package, the honest default is to say nothing until you have
checked. Grep your own source for the four things that make a module unskippable:
a top-level call, a prototype or global assignment, a CSS or asset import, and a
registration into anything module-scoped. If you find none, false is true and
you should say so. If you find some, list them and every barrel that imports
them.
If you consume one, the check is the build you already run. Print the retained
module list, which Rolldown hands to you as chunk.modules, before and after a
dependency bump, and a module that quietly left the graph is visible in a diff
rather than in an incident. That is the same habit as reading
what the dev server actually served
instead of trusting the config, and it matters more here because the two bundlers
Vite has shipped
disagree about other transforms too.
What I did not test: /*#__PURE__*/ annotations, which are the per-expression
version of the same promise and fail in the same direction; and whether Rollup
4.63.1 makes the same three decisions on this graph, which would separate “how
tree shaking works” from “how Rolldown does it”. Everything above is
[email protected] on Node 24.20.0, with minification off so the module list is
readable.
FAQ
Frequently asked
What does "sideEffects": false actually promise?
That evaluating any module in the package produces no observable effect, so the bundler may skip evaluating any module whose bindings are unused. It is an assertion the bundler cannot verify. If a module patches a prototype, registers a plugin, or imports CSS, the assertion is false and the bundler will act on it anyway.
Why did listing my polyfill in the sideEffects array not keep it?
Because the module that imports it also has to be listed. Measured with Rolldown 1.2.7, ["./src/polyfill.js"] alone still crashed: the package index was treated as effect-free, dropped, and the import statement went with it. ["./src/polyfill.js", "./src/index.js"] worked.


