Skip to content

Angular 19 SSR cloud functions ESM build #3645

Open

Description

@chakrachi
  • 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

Activity

  1. google-oss-bot commented on Apr 9, 2025

    @google-oss-bot

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

  2. chakrachi commented on Jun 19, 2025

    @chakrachi
    Author

    ➜ 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

  3. chakrachi commented on Jun 21, 2025

    @chakrachi
    Author

    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: {}
    }

  4. quedicesebas commented on Jul 16, 2026

    @quedicesebas

    Alternative to @angular/fire for Angular 22+ and Native Firebase JS SDK 12+

    Like many of you, our team faced significant roadblocks when upgrading our production projects to Angular 22+ and the latest Firebase JS SDK v12+ due to the current maintenance status and delayed updates of @angular/fire.

    Instead of waiting, we decided to build and publish a lightweight, zoneless-friendly, and modern alternative: ngx-firebase.

    We have just released version 22.0.1 and integrated it into our own production monorepo, and we wanted to share it with the community to help others get unstuck.

    ⚡ What is ngx-firebase?
    It is a drop-in, lightweight DI wrapper around the official Firebase JS SDK (v12+) built specifically for Angular 22+.

    🌟 Key Features:
    Fully Compatible: Built from the ground up for Angular 22+ and the latest Firebase JS SDK v12+.
    Zoneless-Friendly: Works seamlessly in modern Angular applications running without Zone.js.
    Zero API Bloat / Developer Autonomy: It does not try to reinvent or hide the native Firebase API. You import native Firebase methods directly (getFirestore, signInWithEmailAndPassword, etc.) and use ngx-firebase strictly for Angular Dependency Injection and reactive RxJS helper wrappers (docData, collectionSnapshots, user, etc.).
    Future-Proof: If Firebase releases a new SDK update tomorrow, you don't have to wait for a library update; you can immediately use any new native Firebase features alongside our DI wrappers.
    📦 Quick Start:
    bash
    npm install ngx-firebase firebase
    🔗 Links & Resources:
    GitHub Repository: quedicesebas/ngx-firebase
    NPM Package: ngx-firebase
    We are actively maintaining this project and would love to hear your feedback, issues, or pull requests to make it even better. Let's keep moving the Angular + Firebase ecosystem forward! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions