I'm trying to deploy a Vite+React+SSR app to Firebase, but Firebase won't recognize the runtime for my server script. I've created a file – server/index.js – running Express.js for SSR rendering of the app, which works fine locally. In the same file I've added onRequest
from Firebase to handle SSL.
import express from 'express'
import { onRequest } from 'firebase-functions/v2/https'
const app = express()
app.use(/* Express and Vite settings */)
app.listen(process.env.PORT)
export const ssr = onRequest(app)
Here's my Firebase config:
{
"hosting": {
"public": "dist/client",
"ignore": [
"**/.*",
"**/node_modules/**",
"firebase.json",
"firebase-debug.log",
"firebase-debug.*.log"
],
"rewrites": [
{
"source": "**",
"function": "ssr"
}
]
},
"functions": [
{
"source": "server",
"runtime": "nodejs22",
"codebase": "default"
}
]
}
Package.json:
{
"name": "name",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "rimraf dist && pnpm build:client && pnpm build:server",
"build:client": "vite build --outDir dist/client --ssrManifest",
"build:server": "vite build --ssr src/entry-server.tsx --outDir dist/server",
"deploy": "firebase deploy --only functions",
"serve": "pnpm build && firebase emulators:start --only functions",
"shell": "pnpm build && firebase functions:shell",
"start": "firebase functions:shell"
},
// ...Dependencies & devDependencies
"engines": {
"node": "22"
}
}
I've tried with node 20 and node 22, to no avail.