Skip to content

Dev Server throws error when running Angular 17 app non-standalone with SSR #26922

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
griest024 opened this issue Jan 22, 2024 · 3 comments · Fixed by #26928
Closed
1 task done

Dev Server throws error when running Angular 17 app non-standalone with SSR #26922

griest024 opened this issue Jan 22, 2024 · 3 comments · Fixed by #26928

Comments

@griest024
Copy link

griest024 commented Jan 22, 2024

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

16

Description

When running an Angular 17 app with the module setup and SSR enabled, the dev server throws an error.

Building (ng b) works (unless prerender: true) and serving the client bundle directly works as well as running SSR: node dist/repro-app/server/server.mjs.

With prerender enabled, building throws the same error as the dev server.

Removing SSR (deleting ssr and server options in angular.json) causes the dev server to work as expected.

Minimal Reproduction

Run ng s in my repro.

See this branch for a repro of how removing SSR options fixes the issue.

Exception or Error

[vite] Internal server error: Cannot read properties of undefined (reading 'ɵmod')
      at getNgModuleDef (/workspace/repro-app/node_modules/@angular/core/fesm2022/core.mjs:2117:25)
      at assertNgModuleType (/workspace/repro-app/node_modules/@angular/core/fesm2022/core.mjs:2371:10)
      at compileNgModuleFactory (/workspace/repro-app/node_modules/@angular/core/fesm2022/core.mjs:31582:18)
      at _PlatformRef.bootstrapModule (/workspace/repro-app/node_modules/@angular/core/fesm2022/core.mjs:32472:16)
      at eval (/workspace/repro-app/node_modules/@angular/platform-server/fesm2022/platform-server.mjs:17111:39)
      at Generator.next (<anonymous>)
      at eval (/workspace/repro-app/.angular/vite-root/repro-app/chunk-VPSODEBW.mjs:64:61)
      at ZoneAwarePromise (/workspace/repro-app/node_modules/zone.js/fesm2015/zone-node.js:1353:21)
      at Module.__async (/workspace/repro-app/.angular/vite-root/repro-app/chunk-VPSODEBW.mjs:48:10)
      at renderModule (/workspace/repro-app/node_modules/@angular/platform-server/fesm2022/platform-server.mjs:17100:50)

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 17.1.0
Node: 18.19.0
Package Manager: npm 10.2.3
OS: linux x64

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

Package                         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 relevant?

Maybe this isn't a supported usage since standalone is default now? Seems like modules should still be fully supported until they're officially deprecated.

@alan-agius4
Copy link
Collaborator

The problem is caused because when updated the main.server.ts manually the default export in https://github.com/griest024/ng17-repro/blob/c54b47df03c804f8c39ed290efd930e3e4ff5eb5/src/main.server.ts#L1 has been removed.

You could update it the below if you'd also want to keep the named export.

 export {AppServerModule, AppServerModule as default} from './app/app.server.module';

We should however provide a more actionable error message here.

@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken angular/build:application labels Jan 23, 2024
@alan-agius4 alan-agius4 self-assigned this Jan 23, 2024
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jan 23, 2024
…when server bundle is missing default export

This change improves the error message when the server bundle does not export a default export.

Closes angular#26922
@griest024
Copy link
Author

@alan-agius4 That fixed it! Good call. I definitely support a better error message.

alan-agius4 added a commit that referenced this issue Jan 23, 2024
…when server bundle is missing default export

This change improves the error message when the server bundle does not export a default export.

Closes #26922
alan-agius4 added a commit that referenced this issue Jan 23, 2024
…when server bundle is missing default export

This change improves the error message when the server bundle does not export a default export.

Closes #26922

(cherry picked from commit 1f119be)
griest024 added a commit to griest024/daffodil that referenced this issue Jan 23, 2024
griest024 added a commit to griest024/daffodil that referenced this issue Jan 24, 2024
griest024 added a commit to griest024/daffodil that referenced this issue Jan 24, 2024
griest024 added a commit to griest024/daffodil that referenced this issue Jan 24, 2024
griest024 added a commit to griest024/daffodil that referenced this issue Jan 25, 2024
griest024 added a commit to griest024/daffodil that referenced this issue Jan 25, 2024
@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 Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants