Repository navigation
Description
Command
build
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
22.0.x
Description
Hi, Initial total considers main bundle raw size for calculation, but Rolldown optimized version has static imports of many chunks at start so it should be counted towards the total.
I also mentioned the same here before: #27715 (comment) but at that time it was experimental.
Our actual initial total for one of the app was ~2MB, now its 915.41 kB, this was found by Claude, and I confirmed it just now. (manually as Claude is down right now).
Minimal Reproduction
Build the any app with some dependencies and lazy routes with 22.0.x and 22.1.x and check difference between Initial total for both.
this is from generated main bundle with Rolldown based optimizer:
import{a as J$1,n as G$2,p as R$1,t as F$1}from"./chunk-Dss6OLyd.js";
// ...
import{a as z$2,i as te,n as Yt$1,r as de$1,t as U$1}from"./chunk-Db26sq0E.js";
// and many more as start of main bundle jsAll should be counted towards the total. Rollup based version does not have such static chunk imports at start so it was accurate.
Exception or Error
NA
Your Environment
Angular CLI : 22.1.3
Angular : 22.1.0
Node.js : 24.18.0
Package Manager : pnpm 11.18.0
Operating System : darwin arm64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/aria │ 22.1.1 │ 22.1.1 │
│ @angular/build │ 22.1.3 │ ^22.1.3 │
│ @angular/cdk │ 22.1.1 │ 22.1.1 │
│ @angular/cli │ 22.1.3 │ 22.1.3 │
│ @angular/common │ 22.1.0 │ 22.1.0 │
│ @angular/compiler │ 22.1.0 │ 22.1.0 │
│ @angular/compiler-cli │ 22.1.0 │ 22.1.0 │
│ @angular/core │ 22.1.0 │ 22.1.0 │
│ @angular/forms │ 22.1.0 │ 22.1.0 │
│ @angular/platform-browser │ 22.1.0 │ 22.1.0 │
│ @angular/router │ 22.1.0 │ 22.1.0 │
│ ng-packagr │ 22.1.1 │ 22.1.1 │
│ rxjs │ 7.8.2 │ 7.8.2 │
│ typescript │ 6.0.3 │ ~6.0.3 │
│ vitest │ 4.1.10 │ 4.1.10 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?
No response
Activity
[-]Incorrect initial total reporting with Rolldown base optimizer (22.1.x)[/-][+]Incorrect initial total reporting with Rolldown based optimizer (22.1.x)[/+]alan-agius4 commentedon Aug 6, 2026
This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?
You can read here why this is needed. A good way to make a minimal repro is to create a new app via
ng new repro-appand adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.This might be related to your directory structure so its really important to get an accurate repro to diagnose this.
imaksp commentedon Aug 6, 2026
I tracked down the root cause. It is a missing
Map.setin the chunk optimizer, not a metafile problem — I have opened #33793 with a one-line fix.The metafile is correct. Building with
--stats-json,mainreports its chunk imports with the right kind:So
BundlerContext's transitive walk classifies these correctly. They are lost afterwards.Root cause.
optimizeChunksinpackages/angular/build/src/builders/application/chunk-optimizer.tsdeletes every used chunk frominitialFiles, keeping onlymain, then re-walks the optimized graph to restore the onesmainstill imports statically. That walk builds a record but never stores it:Because the entries were deleted just above,
existingRecordis alwaysundefined, so each chunk is analyzed and discarded.initialFilesends up holding only the configured entry points — precisely what "Initial total" sums. The equivalent loop inBundlerContext#bundledoes callinitialFiles.set(...)before pushing.Verified. Adding that one line and rebuilding the same app, nothing else changed: 377.35 kB -> 1.35 MB (75.76 kB -> 314.70 kB transfer), with all seven statically imported chunks moving into Initial chunk files. Cross-checked by walking
index.htmlthrough staticimport/fromedges only: 1172.0 kB JS + 149.3 kB CSS, matching the corrected total.Why I cannot attach a minimal reproduction. The bug is only observable when the optimizer's output still contains
main -> chunkstatic edges. In small applications Rolldown hoists all entry-reachable shared code into the main chunk, so no such chunk survives to be lost — your ownchunk-optimization-server_spec.tsdepends on this, asserting nochunk-*.jsremains as proof the pass ran.On a fresh
ng newwith@angular/cli@22.1.3I tried: 1 lazy route; 8 lazy routes; a shared component used by the eager and lazy graphs; a ~2 MB shared module giving a 1.72 MBmain; and eight ~154 kB lazy routes sharing vendor code. Every one produced zero static chunks frommain, so the totals came out correct and the test would have been vacuous. The affected application has ~114 lazy chunks. Note the misreported chunks are not all large — they range from 919 kB down to 534 bytes — so it is not purely size-driven, and I could not pin down what makes Rolldown retain them at that scale.Given that, a regression test asserting the invariant directly is probably more practical than a fixture app: after
optimizeChunks, every entry inimportsPerFile[mainFile]should be present ininitialFiles. I offered in the PR to add that, or a fixture, if you can suggest a shape that keeps a shared chunk.Environment:
@angular/cliand@angular/build22.1.3,@angular/core22.1.0, Node 24.18.0, production build, defaultNG_BUILD_OPTIMIZE_CHUNKS.imaksp commentedon Aug 6, 2026
NOTE: above comment is generated by Claude code, it could not create reproduction as it happens only if app has so many lazy chunks.
fix(@angular/build): count statically imported chunks in the initial …
fix(@angular/build): count statically imported chunks in the initial …
fix(@angular/build): count statically imported chunks in the initial …
angular-automatic-lock-bot commentedon Oct 18, 2026
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.