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

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\@[email protected]_@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/[email protected]_@[email protected]_7931a348c589a4516c328719e7197a02/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47397:41)
      at TransformPluginContext.error (file:///C:/Project/ssrtest/node_modules/.pnpm/[email protected]_@[email protected]_7931a348c589a4516c328719e7197a02/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47392:16)
      at normalizeUrl (file:///C:/Project/ssrtest/node_modules/.pnpm/[email protected]_@[email protected]_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/[email protected]_@[email protected]_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

Activity

  1. pisxid commented on Jan 17, 2025

    @pisxid
    Angular CLI: 19.1.1
    Node: 22.13.0
    Package Manager: npm 11.0.0
    OS: win32 x64
    
    Angular: 19.1.1
    ... animations, cli, common, compiler, compiler-cli, core, forms
    ... language-service, platform-browser, platform-browser-dynamic
    ... router
    
    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
    @angular/cdk                    19.1.0
    @angular/material               19.1.0
    @schematics/angular             19.1.1
    rxjs                            7.8.1
    typescript                      5.7.3
    zone.js                         0.15.0
    

    Also happens without SSR. Hot reload is not working

  2. anisabboud commented on Jan 21, 2025

    @anisabboud

    Still seeing this issue with @angular/cli 19.1.3 released yesterday.

    [vite] Internal server error: ɵgetOrCreateAngularServerApp is not a function
          at /.../node_modules/@angular/build/src/tools/vite/middlewares/ssr-middleware.js:26:38 (x4)

    (Happens randomly when saving a file.)

  3. alan-agius4 commented on Jan 21, 2025

    @alan-agius4
    Collaborator

    @anisabboud, the issue you're reporting is unrelated to this one. Please submit a new issue with the steps to reproduce. Thank you.

  4. enzofrnt commented on Feb 4, 2025

    @enzofrnt

    I'm still getting this error :

    ɵgetOrCreateAngularServerApp is not a function
    

    It appears when I add something to any component of my app.

  5. Ahmed-Makled commented on Feb 16, 2025

    @Ahmed-Makled

    any soltuions ?

  6. chiragmer77 commented on Feb 19, 2025

    @chiragmer77

    any soltuions ?

  7. adnanibrahem commented on Feb 22, 2025

    @adnanibrahem

    try this:
    constructor(@Inject(DOCUMENT) document: Document) { }

  8. Kgermando commented on Mar 16, 2025

    @Kgermando

    04:00:03 [vite] Internal server error: ɵgetOrCreateAngularServerApp is not a function
    at C:\Users\germa\Documents\DEVELOPER\ANGULAR\PROJECTS\optimatincorporation\node_modules@angular\build\src\tools\vite\middlewares\ssr-middleware.js:30:38
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    04:00:06 [vite] Internal server error: ɵgetOrCreateAngularServerApp is not a function
    at C:\Users\germa\Documents\DEVELOPER\ANGULAR\PROJECTS\optimatincorporation\node_modules@angular\build\src\tools\vite\middlewares\ssr-middleware.js:30:38
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) (x2)

  9. angular-automatic-lock-bot commented on Apr 16, 2025

    @angular-automatic-lock-bot

    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.

  10. locked and limited conversation to collaborators on Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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