angular/angularfire

Angular 19 SSR cloud functions ESM build

chakrachi opened this issue · 3 comments

  • unable to serve/deploy ssr functions esm build artifacts with vanilla cloud functions
  • able to ng serve, ng build (build-angular:application), and node ./server.mjs
  • other functions unrelated to SSR are working (server backend) as intended

Heres my SSR setup:

universal.ts

import { onRequest } from 'firebase-functions/v2/https';
import { render } from '../../render.js';
import express, { Request, Response, NextFunction } from 'express';
import * as server from '../../../dist/stamp-app/server/server.mjs';
export const ssrApp = express() as any;

ssrApp.use(express.static('dist/stamp-app/browser'));
ssrApp.get('*', async (req: Request, res: Response, next: NextFunction) => {
	const ssr: any = await render(server, req, res, next);
	res.send(ssr);
});

export const universal = onRequest(
	{ maxInstances: 10, timeoutSeconds: 1200, cpu: 1, memory: '2GiB', region: ['us-central1'] },
	ssrApp
);

render.js

import { Request, Response, NextFunction } from "express";

export async function configServerApp(app: any, req: Request, res: Response, next: NextFunction) {
  //configure app here & retrieve HTML
  let template;
  if (req.path === '/') {
    // template = await fetch('@dist/stamp-app/browser/index.csr.html');
    next();
  }
  template = `<div>HTML CONTENT FOR SSR APP</div>`;
  return template;
}
export async function render(app: any, req: Request, res: Response, next: NextFunction) {
  const ssrApp = await configServerApp(app, req, res, next);
  return ssrApp;
}

am I missing something..? thanks for any help in advance

This issue does not seem to follow the issue template. Make sure you provide all the required information.

➜ functions git:(grow) ✗ firebase serve --only functions
⚠ functions: Application Default Credentials detected. Non-emulated services will access production using these credentials. Be careful!
i functions: Watching "/stampDEV/stamp-app/functions" for Cloud Functions...
⚠ functions: Your requested "node" version "22" doesn't match your global version "20". Using node@20 from host.
Serving at port 8579

JIT compilation failed for injectable [class PlatformLocation]

Error: The injectable 'PlatformLocation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.

The injectable is part of a library that has been partially compiled.
However, the Angular Linker has not processed the library such that JIT compilation is used as fallback.

Ideally, the library is processed using the Angular Linker to become fully AOT compiled.
Alternatively, the JIT compiler should be loaded by bootstrapping using '@angular/platform-browser-dynamic' or '@angular/platform-server',
or manually provide the compiler with 'import "@angular/compiler";' before bootstrapping.
at getCompilerFacade (file:/stampDEV/stamp-app/functions/node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:209:15)
at Module.ɵɵngDeclareFactory (file:///stampDEV/stamp-app/functions/node_modules/@angular/core/fesm2022/core.mjs:4041:22)
at <static_initializer> (file:///stampDEV/stamp-app/functions/node_modules/@angular/common/fesm2022/location-BIEtBxGx.mjs:53:22)
at file:///stampDEV/stamp-app/functions/node_modules/@angular/common/fesm2022/location-BIEtBxGx.mjs:24:1
at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
at async loadModule (stampDEV/stamp-app/functions/node_modules/firebase-functions/lib/runtime/loader.js:48:20)
at async loadStack (stampDEV/stamp-app/functions/node_modules/firebase-functions/lib/runtime/loader.js:157:17)
at async /stampDEV/stamp-app/functions/node_modules/firebase-functions/lib/bin/firebase-functions.js:56:27

🚀 Graphql Server ready @ http://localhost:2200/graphql

⬢ functions: Failed to load function definition from source: FirebaseError: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error

latest error referencing firebase, anyone have a working version?

⚠ functions: Application Default Credentials detected. Non-emulated services will access production using these credentials. Be careful!
i functions: Watching "/stampDEV/stamp-app/functions" for Cloud Functions...
⚠ functions: Your requested "node" version "22" doesn't match your global version "20". Using node@20 from host.
Serving at port 8773

🚀 Graphql Server ready @ http://localhost:2200/graphql

✔ functions: Loaded functions definitions from source: app, sendwelcomeemail, ssr.
✔ functions[us-central1-app]: http function initialized (http://localhost:5000/firebase-stampapp/us-central1/app).
i functions[us-central1-sendwelcomeemail]: function ignored because the eventarc emulator does not exist or is not running.
✔ functions[us-central1-ssr]: http function initialized (http://localhost:5000/firebase-stampapp/us-central1/ssr).

🚀 Graphql Server ready @ http://localhost:2200/graphql
i functions: Beginning execution of "us-central1-ssr"
ERROR _FirebaseError: Firebase: FirebaseServerApp is not for use in browser environments. (app/invalid-server-app-environment).
at initializeServerApp (file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:118649:25)
at file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:119231:44
at file://stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:119188:41
at NoopNgZone.runOutsideAngular (file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:15216:12)
at runOutsideAngular (file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:119188:17)
at file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:119231:17
at file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:153133:14
at file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:119293:46
at NoopNgZone.runOutsideAngular (file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:15216:12)
at Object.useFactory (file:///stampDEV/stamp-app/functions/dist/stamp-app/server/main.server.mjs:119293:22) {
code: 'app/invalid-server-app-environment',
customData: {}
}