Skip to content

Angular 17 SSR RuntimeError: NG04002 #54005

@stanchev89

Description

@stanchev89

Which @angular/* package(s) are the source of the bug?

core, platform-browser-dynamic, platform-browser, platform-server, router

Is this a regression?

Yes

Description

I've identified an unusual behavior during my examination of Angular SSR scenarios, and I'm quite skeptical about potential pitfalls if we opt to migrate our current project to SSR. The scenario is straightforward: our app has a routing structure with a parent 'post' route and two children—one with an empty "" path using pathMatch: full, and another with the "entity" path. Navigating through these paths initially doesn't reveal any issues.

However, if we reload the page while on the home page and then navigate to other paths, everything functions normally. Yet, if we reload the page while on the 'post entity' page, things appear fine initially. Still, upon navigating to the 'post list' and then back 'post entity' we encounter the following error:

ERROR RuntimeError: NG04002: Cannot match any routes. URL Segment: 'post/post-entity.component.css.map'
(the error is shown into the terminal where the process is started)

In addition, I've implemented console logs of 'BEFORE SERVER RENDER!' for each commonEngine.render() execution in the server.ts file. After the bug occurs, we notice that the app is being rendered for each iteration, contrary to the expected default behavior of rendering just once.

Steps to reproduce:

  1. Open the repo and install deps.
  2. Run into the IDE terminal: npm run watch
  3. Open another terminal and run npm run serve:ssr:test-ssr
  4. Do the steps described above
  5. The error is displayed in the 'second' terminal.

Please provide a link to a minimal reproduction of the bug

https://github.com/stanchev89/ng-ssr-issue

Please provide the exception or error you saw

ERROR RuntimeError: NG04002: Cannot match any routes. URL Segment: 'post/post-entity.component.css.map'
    at Recognizer.noMatchError (file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-LORNH6TK.mjs:4500:12)
    at file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-LORNH6TK.mjs:4526:20
    at file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-IIHA4DIP.mjs:1727:33
    at OperatorSubscriber._error (file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-IIHA4DIP.mjs:820:9)
    at OperatorSubscriber.error (file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-IIHA4DIP.mjs:556:12)
    at OperatorSubscriber._error (file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-IIHA4DIP.mjs:579:24)
    at OperatorSubscriber.error (file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-IIHA4DIP.mjs:556:12)
    at OperatorSubscriber._error (file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-IIHA4DIP.mjs:579:24)
    at OperatorSubscriber.error (file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-IIHA4DIP.mjs:556:12)
    at OperatorSubscriber._error (file:///Users/stanchev/Documents/GitHub/ng-ssr-issue/dist/test-ssr/server/chunk-IIHA4DIP.mjs:579:24) {
  code: 4002
}

Please provide the environment you discovered this bug in (run ng version)

@angular-devkit/architect       0.1701.0
@angular-devkit/build-angular   17.1.0
@angular-devkit/core            17.1.0
@angular-devkit/schematics      17.1.0
@schematics/angular             17.1.0
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.3

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions