Repository navigation
Closed
Description
[REQUIRED] Environment info
firebase-tools: 13.0.2
Platform: Windows, Linux
[REQUIRED] Test case
I deploy a fully workable version from the emulator in Firebase Functions of the Angular SSR application.
[REQUIRED] Steps to reproduce
- Enabled experiment webframeworks.
- Create an application angular ssr from cli with standalone componenet
- run it locally
- deploy it in the firebase.
During Local build I have next warning
▲ [WARNING] Module 'undici' used by 'node_modules/@firebase/auth/dist/node-esm/index.js' is not ESM
▲ [WARNING] Module '@grpc/grpc-js' used by 'node_modules/@firebase/firestore/dist/index.node.mjs' is not ESM
▲ [WARNING] Module '@grpc/proto-loader' used by 'node_modules/@firebase/firestore/dist/index.node.mjs' is not ESM
▲ [WARNING] Module 'undici' used by 'node_modules/@firebase/functions/dist/esm-node/index.node.esm.js' is not ESM
▲ [WARNING] Module 'undici' used by 'node_modules/@firebase/storage/dist/node-esm/index.node.esm.js' is not ESM
CommonJS or AMD dependencies can cause optimization bailouts.
For more information see: https://angular.io/guide/build#configuring-commonjs-dependencies[REQUIRED] Expected behavior
Should work exactly as in the emulator.
[REQUIRED] Actual behavior
SSR Page returns: Service Unavailable
Logs
Default STARTUP TCP probe succeeded after 1 attempt for container "ssr-project-name-1" on port 8080.
Uncaught exception
Error: listen EADDRINUSE: address already in use :::8080
at Server.setupListenHandle [as _listen2] (node:net:1872:16)
at listenInCluster (node:net:1920:12)
at Server.listen (node:net:2008:7)
at te.listen (file:///workspace/dist/ssr-project-name/server/server.mjs:81:3210)
at $k (file:///workspace/dist/ssr-project-name/server/server.mjs:99:5579)
at file:///workspace/dist/ssr-project-name/server/server.mjs:99:5665
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)
Error: Process exited with code 16
at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:92:22)
at process.emit (node:events:514:28)
at process.emit (node:domain:488:12)
at process.exit (node:internal/process/per_thread:193:15)
at sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:44:9)
at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:84:44)
at process.emit (node:events:526:35)
at process.emit (node:domain:488:12)
at process._fatalException (node:internal/process/execution:159:25)Reacted by Djery-Tom and makss68
Activity
hittten commentedon Jan 2, 2024
I have the same problem, I have published a repo with the minimum to recreate the SSR problem with angular 17: https://github.com/hittten/angularSSR17
Clone & Setup:
Logs:
Deploy to firebase hosting with SSR function
Server logs:
{ "textPayload": "The request failed because either the HTTP response was malformed or connection to the instance had an error. Additional troubleshooting documentation can be found at: https://cloud.google.com/run/docs/troubleshooting#malformed-response-or-connection-error", "insertId": "659475b700062cb90f40d1e3", "httpRequest": { "requestMethod": "GET", "requestUrl": "https://fh-8d3e45905df6630b---ssrfirebase-project-ou4f5ridea-ew.a.run.app/home", "requestSize": "1456", "status": 503, "responseSize": "896", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "remoteIp": "xx.xx.xx.xx", "serverIp": "xx.xx.xx.xx", "latency": "0.003751506s", "protocol": "HTTP/1.1" }, "resource": { "type": "cloud_run_revision", "labels": { "revision_name": "ssrfirebase-project-00049-suv", "service_name": "ssrfirebase-project", "location": "europe-west1", "configuration_name": "ssrfirebase-project", "project_id": "firebase-project" } }, "timestamp": "2024-01-02T20:44:39.398780Z", "severity": "ERROR", "labels": { "instanceId": "0087599d42b9441d6d09db1939ddd4cf4272e2926a4f28f80a4a7435e09c496814eec2631eed5c4f41d11da415f43dbdd4584eebf9300d2775bc6e376358218de7", "goog-managed-by": "cloudfunctions" }, "logName": "projects/firebase-project/logs/run.googleapis.com%2Frequests", "trace": "projects/firebase-project/traces/2cbddcb349eb67f0b870211ea2050942", "receiveTimestamp": "2024-01-02T20:44:39.688582619Z", "spanId": "15678518055140550732" }Info
basically I have created a project like this:
I also disable pre-render in angular.json:
{ "scripts": [], "server": "src/main.server.ts", "prerender": false, "ssr": { "entry": "server.ts" } }and I have done the settings of the routes for lazy load. I have not installed @angular/fire because it is not necessary to recreate the SSR error.
ng version
firebase-tools version:
9kubczas4 commentedon Jan 8, 2024
Hi @hittten,
I discovered a workaround that can be applied to the code of an Angular application.
For example in the
server.ts, https://github.com/hittten/angularSSR17/blob/2ed948581d32b20b45c66e8c4f4f72046d9a5cf4/server.ts#L46-L54 adjust a way of settingportvariable. It looks like thePORTenvironment variable is already used. The solution could be:const port = process.env['NG_SSR_PORT'] || 4000;// change the environment variable nameconst port = 4000;// hardcode the port value without using environment variableI don't know what exactly is the root cause, but as I mentioned it looks like
PORTenvironment variable is already used.mvergarair commentedon Jan 12, 2024
Getting the same error:
rdlabo commentedon Jan 19, 2024
@9kubczas4 Thanks for information. This works well!
Add info:
If you deploy index.html, Functions will not work and must be IGNORED.
{ "source": ".", "frameworksBackend": { "region": "asia-east1" }, "ignore": [ + "index.html",JGSolutions commentedon Jan 21, 2024
@rdlabo thanks. Removing this process.env['NG_SSR_PORT'] worked
But will this be fixed in future releases in angular
MoCodeCom commentedon Jan 26, 2024
Thank you for your comment, but in which file can I find it?
{
"source": ".",
"frameworksBackend": {
"region": "asia-east1"
},
"ignore": [
MoCodeCom commentedon Jan 26, 2024
Thank you for your comment, but in which file can I find it? to make an addition
gguy0406 commentedon Feb 20, 2024
Reserved environment variables are listed here: https://firebase.google.com/docs/functions/config-env?gen=2nd#reserved-names
gguy0406 commentedon Feb 20, 2024
It appears that the run() function generated by Angular CLI is unnecessary. I use an firebase instance in my backend, it seems to execute firebase initializeApp() twice, leading to an error.
hittten commentedon Feb 22, 2024
@9kubczas4 your workaround works perfectly.
Any update about this? this issue doesn't happen in angular 16.
makss68 commentedon Mar 11, 2024
Same problem here. Any news ?
fix(@schematics/angular): rename SSR port env variable
9kubczas4 commentedon Mar 22, 2024
Please for now try to apply this workaround for Angular 17: #6651 (comment).
I created a fix in
angular-cli- angular/angular-cli#27333, once it's merged then it'll be available in one of the future Angular releases.fix(@schematics/angular): rename SSR port env variable
fix(@schematics/angular): rename SSR port env variable