-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Angular 19 SSR with Firebase hosting or Firebase App Hosting Fail #29488
Comments
As the error suggests app hosting is expecting an export const app = () => expressApp; |
@alan-agius4 Thanks for the recommendation, I actually have a workaround by changing the server.ts file of Angular and adapting it the old way in version 18 and I got it working. You can see the commit: hittten/angular19ssr@fbb9090 but the best workaround that I found reading the documentation: https://angular.dev/guide/hybrid-rendering#configuring-a-nodejs-server and changing it a little bit was this: hittten/angular19ssr@e22339c I had also opened the same issue in the firebase-tools repository: firebase/firebase-tools#8141 and I found this on firebase-tools side: firebase/firebase-tools#8145 Additionally, I have tried to get REQUEST and RESPONSE_INIT to work (https://angular.dev/guide/hybrid-rendering#accessing-request-and-response-via-di) and there is no way to get it to work. import {Component, RESPONSE_INIT, REQUEST, inject} from '@angular/core';
@Component({
selector: 'app-not-found-page',
imports: [],
template: `
<h1>404 Not Found</h1>
`,
styles: ``
})
export class NotFoundPageComponent {
private response = inject(RESPONSE_INIT)
private request = inject(REQUEST)
constructor() {
if (this.response !== null) {
this.response.status = 404
}
if (this.request !== null) {
console.log(this.request.url)
}
console.log("request", this.request)
console.log("response", this.response)
}
}
In both cases request and response are undefined on the server side.
|
The tokens will not work with the |
This update is required for Firebase functions compatibility. Closes angular#29488
Which @angular/* package(s) are the source of the bug?
core, platform-server
Is this a regression?
Yes
Description
Angular 19 setup with SSR fails when trying to deploy it with firebase hosting or app hosting.
I've created a very basic angular:
ng new angular19ssr
✔ Which stylesheet format would you like to use? Sass (SCSS) [ https://sass-lang.com/documentation/syntax#scss ]
✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? Yes
✔ Would you like to use the Server Routing and App Engine APIs (Developer Preview) for this server application? No
CREATE angular19ssr/README.md (1475 bytes)
CREATE angular19ssr/.editorconfig (314 bytes)
CREATE angular19ssr/.gitignore (587 bytes)
CREATE angular19ssr/angular.json (2938 bytes)
CREATE angular19ssr/package.json (1281 bytes)
CREATE angular19ssr/tsconfig.json (915 bytes)
CREATE angular19ssr/tsconfig.app.json (489 bytes)
CREATE angular19ssr/tsconfig.spec.json (434 bytes)
CREATE angular19ssr/.vscode/extensions.json (130 bytes)
CREATE angular19ssr/.vscode/launch.json (470 bytes)
CREATE angular19ssr/.vscode/tasks.json (938 bytes)
CREATE angular19ssr/src/main.ts (250 bytes)
CREATE angular19ssr/src/index.html (298 bytes)
CREATE angular19ssr/src/styles.scss (80 bytes)
CREATE angular19ssr/src/main.server.ts (264 bytes)
CREATE angular19ssr/src/server.ts (1764 bytes)
CREATE angular19ssr/src/app/app.component.scss (0 bytes)
CREATE angular19ssr/src/app/app.component.html (19903 bytes)
CREATE angular19ssr/src/app/app.component.spec.ts (934 bytes)
CREATE angular19ssr/src/app/app.component.ts (289 bytes)
CREATE angular19ssr/src/app/app.config.ts (438 bytes)
CREATE angular19ssr/src/app/app.routes.ts (77 bytes)
CREATE angular19ssr/src/app/app.config.server.ts (351 bytes)
CREATE angular19ssr/public/favicon.ico (15086 bytes)
✔ Packages installed successfully.
Successfully initialized git.
Afterwards, I changed the configuration of the angular.json:
https://github.com/hittten/angular19ssr/blob/main/angular.json
https://github.com/hittten/angular19ssr/blob/main/src/prerender.routes.txt
This means that only the pre-render route should be pre-rendered and the rest should be SSR.
https://github.com/hittten/angular19ssr/blob/main/src/app/app.routes.ts
And when you try to load any route with SSR you get this error:
Service Unavailable
You can see this in: https://twistseed-poc.web.app/ssr
The only route that works is https://twistseed-poc.web.app/pre-render but it takes a long time and the root https://twistseed-poc.web.app
also a route like https://twistseed-poc.web.app/does-not-exist but return: "Internal Server Error"
Please provide a link to a minimal reproduction of the bug
https://github.com/hittten/angular19ssr
Please provide the exception or error you saw
The deployment works, i.e. the app deploys without any problem, but then it doesn't work as it should. Error messages are seen in the logs:
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
No response
Update
The best workaround, see this commit: hittten/angular19ssr@e22339c
The text was updated successfully, but these errors were encountered: