angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Running two ng serve instances (same project, different configurations) causes “504 Outdated Optimize Dep” errors in Angular CLI 20.3.8

Open tlevequealithya opened this issue 2 months ago • 5 comments

Command

serve

Is this a regression?

  • [x] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

20.3.6

Description

Since updating to Angular v20.3.9 / CLI v20.3.8, it’s no longer possible to run two ng serve instances for the same project (e.g. localized builds) in parallel. The second instance fails to load with a 504 (Outdated Optimize Dep) error for one or more chunks (e.g. chunk-5V7QYGNA.js).

This setup worked correctly in previous Angular 20.3.6 versions (before the CLI migrated the dev-server to the Vite-based implementation).

The issue appears to be caused by both ng serve processes sharing the same Vite optimizer cache directory inside .angular/cache/.../vite. When one process updates or invalidates the cache, the other process detects stale metadata and refuses to serve pre-bundled chunks.

Minimal Reproduction

package.json scripts "scripts": { "start": "ng serve --host 0.0.0.0", "startfr": "ng serve -c fr --host 0.0.0.0", "startfr-alt": "ng serve -c fr --host 0.0.0.0 --port 4201", "start:both": "concurrently "npm run start" "npm run startfr-alt"" }

Steps to reproduce 1. Run npm run start:both. 2. Wait for both dev servers to start. 3. Observe that the second instance fails to load in the browser console with: Failed to load resource: the server responded with a status of 504 (Outdated Optimize Dep)

Exception or Error

Failed to load resource: the server responded with a status of 504 (Outdated Optimize Dep)

Your Environment

Angular CLI: 20.3.8
Node: 24.1.0
Package Manager: yarn 4.9.2
OS: darwin arm64
    

Angular: 20.3.9
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------
@angular-devkit/architect       0.2003.8
@angular-devkit/build-angular   20.3.8
@angular-devkit/core            20.3.8
@angular-devkit/schematics      20.3.8
@angular/cdk                    20.2.11
@angular/cli                    20.3.8
@angular/material               20.2.11
@schematics/angular             20.3.8
rxjs                            7.8.2
typescript                      5.8.3
zone.js                         0.15.1

Anything else relevant?

No response

tlevequealithya avatar Nov 05 '25 13:11 tlevequealithya

I am not able to replicate this, kindly provide a runnable reproduction.

npx concurrently "npm run start" "npm run start-1 -- --port=4201"
[0] 
[0] > [email protected] start
[0] > ng serve
[0] 
[1] 
[1] > [email protected] start-1
[1] > ng serve --port=4201
[1] 
[0] ❯ Building...
[1] ❯ Building...
[1] ✔ Building...
[1] Browser bundles     
[1] Initial chunk files  | Names               |  Raw size
[1] main.js              | main                |   5.20 kB | 
[1] chunk-YQOESBWP.js    | -                   | 754 bytes | 
[1] chunk-WZUMUPIL.js    | -                   | 186 bytes | 
[1] styles.css           | styles              |  96 bytes | 
[1] 
[1]                      | Initial total       |   6.24 kB
[1] 
[1] Lazy chunk files     | Names               |  Raw size
[1] chunk-63VTEMFA.js    | index-component     |   6.65 kB | 
[1] chunk-MQRZTRVP.js    | register-component  |   6.55 kB | 
[1] chunk-MDYDNWI5.js    | not-found-component |   2.76 kB | 
[1] chunk-4GZ7RC3W.js    | register-routing    | 507 bytes | 
[1] chunk-JR6OS7QB.js    | -                   | 164 bytes | 
[1] 
[1] 
[1] Server bundles      
[1] Initial chunk files  | Names               |  Raw size
[1] main.server.mjs      | main.server         |   8.42 kB | 
[1] server.mjs           | server              |   1.81 kB | 
[1] chunk-FFILDKJJ.mjs   | -                   | 788 bytes | 
[1] polyfills.server.mjs | polyfills.server    | 243 bytes | 
[1] chunk-BEVIHS67.mjs   | -                   | 221 bytes | 
[1] 
[1] Lazy chunk files     | Names               |  Raw size
[1] chunk-UC7GKQ5U.mjs   | index-component     |   6.69 kB | 
[1] chunk-RWCW36NQ.mjs   | register-component  |   6.59 kB | 
[1] chunk-P5SBEWHL.mjs   | not-found-component |   2.79 kB | 
[1] chunk-4Q4FV3UN.mjs   | register-routing    | 543 bytes | 
[1] chunk-NMGLBC4J.mjs   | -                   | 199 bytes | 
[1] 
[1] Application bundle generation complete. [2.039 seconds] - 2025-11-05T15:10:58.528Z
[1] 
[1] Watch mode enabled. Watching for file changes...
[1] NOTE: Raw file sizes do not reflect development server per-request transformations.
[0] ✔ Building...
[0] Browser bundles     
[0] Initial chunk files  | Names               |  Raw size
[0] main.js              | main                |   5.20 kB | 
[0] chunk-YQOESBWP.js    | -                   | 754 bytes | 
[0] chunk-WZUMUPIL.js    | -                   | 186 bytes | 
[0] styles.css           | styles              |  96 bytes | 
[0] 
[0]                      | Initial total       |   6.24 kB
[0] 
[0] Lazy chunk files     | Names               |  Raw size
[0] chunk-63VTEMFA.js    | index-component     |   6.65 kB | 
[0] chunk-MQRZTRVP.js    | register-component  |   6.55 kB | 
[0] chunk-MDYDNWI5.js    | not-found-component |   2.76 kB | 
[0] chunk-4GZ7RC3W.js    | register-routing    | 507 bytes | 
[0] chunk-JR6OS7QB.js    | -                   | 164 bytes | 
[0] 
[0] 
[0] Server bundles      
[0] Initial chunk files  | Names               |  Raw size
[0] main.server.mjs      | main.server         |   8.42 kB | 
[0] server.mjs           | server              |   1.81 kB | 
[0] chunk-FFILDKJJ.mjs   | -                   | 788 bytes | 
[0] polyfills.server.mjs | polyfills.server    | 243 bytes | 
[0] chunk-BEVIHS67.mjs   | -                   | 221 bytes | 
[0] 
[0] Lazy chunk files     | Names               |  Raw size
[0] chunk-UC7GKQ5U.mjs   | index-component     |   6.69 kB | 
[0] chunk-RWCW36NQ.mjs   | register-component  |   6.59 kB | 
[0] chunk-P5SBEWHL.mjs   | not-found-component |   2.79 kB | 
[0] chunk-4Q4FV3UN.mjs   | register-routing    | 543 bytes | 
[0] chunk-NMGLBC4J.mjs   | -                   | 199 bytes | 
[0] 
[0] Application bundle generation complete. [2.267 seconds] - 2025-11-05T15:10:58.753Z
[0] 
[0] Watch mode enabled. Watching for file changes...
[0] NOTE: Raw file sizes do not reflect development server per-request transformations.
[1]   ➜  Local:   http://localhost:4201/
[0]   ➜  Local:   http://localhost:4200/
[0] ❯ Changes detected. Rebuilding...
[1] ❯ Changes detected. Rebuilding...
[1] ✔ Changes detected. Rebuilding...
[1] Browser bundles    
[1] Initial chunk files | Names           | Raw size
[1] main.js             | main            |  5.20 kB | 
[1] 
[1] Lazy chunk files    | Names           | Raw size
[1] chunk-D63AFNL4.js   | index-component |  6.65 kB | 
[1] 
[1] 
[1] Server bundles     
[1] Initial chunk files | Names           | Raw size
[1] main.server.mjs     | main.server     |  8.42 kB | 
[1] 
[1] Lazy chunk files    | Names           | Raw size
[1] chunk-OD5TZYHM.mjs  | index-component |  6.69 kB | 
[1] 
[1] Application bundle generation complete. [0.265 seconds] - 2025-11-05T15:11:31.936Z
[1] 
[0] ✔ Changes detected. Rebuilding...
[0] Browser bundles    
[0] Initial chunk files | Names           | Raw size
[0] main.js             | main            |  5.20 kB | 
[0] 
[0] Lazy chunk files    | Names           | Raw size
[0] chunk-D63AFNL4.js   | index-component |  6.65 kB | 
[0] 
[0] 
[0] Server bundles     
[0] Initial chunk files | Names           | Raw size
[0] main.server.mjs     | main.server     |  8.42 kB | 
[0] 
[0] Lazy chunk files    | Names           | Raw size
[0] chunk-OD5TZYHM.mjs  | index-component |  6.69 kB | 
[0] 
[0] Application bundle generation complete. [0.284 seconds] - 2025-11-05T15:11:31.955Z
[0] 
[0] Component update sent to client(s).
[1] Component update sent to client(s).
^C[0] npm run start exited with code SIGINT
[1] npm run start-1 -- --port=4201 exited with code SIGINT

alan-agius4 avatar Nov 05 '25 15:11 alan-agius4

When creating a demo project, I found the way to fix this. I replace my builder in the server config from "@angular-devkit/build-angular:dev-server" to "@angular/build:dev-server".

tlevequealithya avatar Nov 05 '25 21:11 tlevequealithya

I am finally back with the same problem. I am unable to have HMR enabled and a double instance running at the same time. Here is a demo project. Just npm run start:both and you will see that only one is working. The angular.json and package.json are almost an identical copies of my real project. https://github.com/tlevequealithya/doubleinstance In the branch "angularupdate"

I know that if I set outputHashing to "all" on one of the 2 development config, the 2 instances are working, but HMR is then disabled....

tlevequealithya avatar Nov 10 '25 19:11 tlevequealithya

The issue is that enabling localization includes different modules in the bundle. This causes the dependency optimizer to fail because, technically, it is still the same application.

OOC what is the use case for running two instances of the same application concurrently?

alan-agius4 avatar Nov 11 '25 08:11 alan-agius4

The issue is that enabling localization includes different modules in the bundle. This causes the dependency optimizer to fail because, technically, it is still the same application.

OOC what is the use case for running two instances of the same application concurrently?

Having it running in the 2 locale. Because text in english and french do not use the same space and we always must make sure that everything is fine in both languages.

tlevequealithya avatar Nov 11 '25 13:11 tlevequealithya