[Bug]: variables do not get tree-shaken in some cases
Author: nstepienCreated Sep 3, 2026Updated Sep 10, 2026
Reproduction link or steps
What is expected?
Unused variables/expressions should be removed from the resulting bundle.
//#region constants.ts
const second = 1e3;
//#endregion
//#region index.ts
console.log(second);
//#endregionWhat is actually happening?
Rolldown removes unused variables, but leaves behind useless expressions.
//#region constants.ts
const second = 1e3;
60 * second;
const a = "aaaa";
`${a}`;
`${a}`;
//#endregion
//#region index.ts
console.log(second);
//#endregionSystem Info
System:
OS: Windows 11 10.0.26200
CPU: (32) x64 AMD Ryzen 9 9950X3D 16-Core Processor
Memory: 35.15 GB / 63.58 GB
Binaries:
Node: 26.8.1 - C:\Program Files\nodejs\node.EXE
npm: 12.0.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 152.0.7977.76
Edge: Chromium (152.0.4191.53)
Firefox: 155.0 - C:\Program Files\Mozilla Firefox\firefox.exeAny additional comments?
Additionally:
- if I remove the variable declarations, but leave behind their expressions, the expressions will not be removed in the output either
export const second = 1000; 60 * second; const a = 'aaaa'; `${a}`; `${a}`; - removing one of the
`${a}`DOES remove all the strings- input:
export const second = 1000; 60 * second; const a = 'aaaa'; `${a}`; // `${a}`; - output:
//#region constants.ts const second = 1e3; 60 * second; //#endregion //#region index.ts console.log(second); //#endregion
- input:
- enabling
minify: trueorminify: 'dce-only'does not help, surprisingly - with
minify: true:- changing
1000to100or1e2DOES remove the60 * secondexpression- changing
1000to1e3does not help
- changing
- changing
'aaaa'to'aaa'DOES remove all the strings minify: 'dce-only'does not help with the above- input:
export const second = 100; 60 * second; const a = 'aaa'; `${a}`; `${a}`; - output:
console.log(100);
- changing
Source: rolldown/rolldown