Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
Ruisi-Lu opened this issue Jan 17, 2025 · 9 comments

Comments

@Ruisi-Lu
Copy link

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

@pisxid
Copy link

pisxid commented Jan 17, 2025

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

@anisabboud
Copy link

anisabboud commented Jan 21, 2025

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.)

@alan-agius4
Copy link
Collaborator

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

@enzofrnt
Copy link

enzofrnt commented Feb 4, 2025

I'm still getting this error :

ɵgetOrCreateAngularServerApp is not a function

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

@Ahmed-Makled
Copy link

any soltuions ?

1 similar comment
@chiragmer77
Copy link

any soltuions ?

@adnanibrahem
Copy link

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

@Kgermando
Copy link

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)

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants