Skip to content

Error: ɵgetOrCreateAngularServerApp is not a function when using lazy loading routes in 19.1.x SSR when HMR enabled #29379

Closed as duplicate of#29369
@Ruisi-Lu

Description

@Ruisi-Lu

Command

serve

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

No response

Description

When implementing lazy loading routes, the application fails during runtime with the following error:

上午10:49:31 [vite] Internal server error: ɵgetOrCreateAngularServerApp is not a function
      at C:\Project\ssrtest\node_modules\.pnpm\@angular+build@19.1.1_@angu_5cd6b3085b9f53655a442b950631221f\node_modules\@angular\build\src\tools\vite\middlewares\ssr-middleware.js:26:38
上午10:49:31 [vite] Pre-transform error: Failed to resolve import "./chunk-LPMLDZGR.js" from ".angular/vite-root/ssrtest/main.js". Does the file exist?
  Plugin: vite:import-analysis
  File: C:/Project/ssrtest/.angular/vite-root/ssrtest/main.js:6:31
  14 |    __spreadValues({
  15 |      path: "",
  16 |      loadChildren: () => import("./chunk-LPMLDZGR.js")
     |                                 ^
  17 |    }, false ? { \u0275entryName: "src/app/test/lazy.route.ts" } : {})
  18 |  ];
上午10:49:31 [vite] Internal server error: Failed to resolve import "./chunk-LPMLDZGR.js" from ".angular/vite-root/ssrtest/main.js". Does the file exist?
  Plugin: vite:import-analysis
  File: C:/Project/ssrtest/.angular/vite-root/ssrtest/main.js:6:31
  14 |    __spreadValues({
  15 |      path: "",
  16 |      loadChildren: () => import("./chunk-LPMLDZGR.js")
     |                                 ^
  17 |    }, false ? { \u0275entryName: "src/app/test/lazy.route.ts" } : {})
  18 |  ];
      at TransformPluginContext._formatError (file:///C:/Project/ssrtest/node_modules/.pnpm/vite@6.0.7_@types+node@18.1_7931a348c589a4516c328719e7197a02/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47397:41)
      at TransformPluginContext.error (file:///C:/Project/ssrtest/node_modules/.pnpm/vite@6.0.7_@types+node@18.1_7931a348c589a4516c328719e7197a02/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47392:16)
      at normalizeUrl (file:///C:/Project/ssrtest/node_modules/.pnpm/vite@6.0.7_@types+node@18.1_7931a348c589a4516c328719e7197a02/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:45642:23)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async file:///C:/Project/ssrtest/node_modules/.pnpm/vite@6.0.7_@types+node@18.1_7931a348c589a4516c328719e7197a02/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:45761:39

Minimal Reproduction

Steps to reproduce the issue:

  1. Create a new Angular project with SSR using version 19.1.0 or 19.1.1
  2. Configure routes using loadChildren
  3. Run the server
  4. Change component HTML template
  5. Observe the error in the terminal.

Reproduction project: https://github.com/Ruisi-Lu/angular19.1-lazyload-route-bug-reproduction-

Exception or Error


Your Environment

Angular CLI: 19.1.1
Node: 20.18.1
Package Manager: pnpm 10.0.0
OS: win32 x64

Angular: 19.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1901.1
@angular-devkit/build-angular   19.1.1
@angular-devkit/core            19.1.1
@angular-devkit/schematics      19.1.1
@schematics/angular             19.1.1
rxjs                            7.8.1
typescript                      5.7.3
zone.js                         0.15.0

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions