Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Astro SSR Firebase Hosting: An unexpected error at build step 2 during firebase deployment

Hello Everyone,

During deploying an Astro SSR site to Firebase hosting, I got an unexpected error. Before deploying, it runs without errors using "firebase serve" locally. The details are as follows.

The error message in the logs

type: "build"
}
severity: "INFO"
textPayload: "ERROR: build step 2 "europe-west1-docker.pkg.dev/serverless-runtimes/google-22-full/builder/nodejs:nodejs_20240715_RC00" failed: step exited with non-zero status: 1"

I checked the node and npm package versions with firebase CLI; node: v20.15.1, npm: 10.8.2.

The relevant configurations files:

astro.config.msj 

...

  output: "hybrid",
  experimental: {
    clientPrerender: true,
    directRenderScript: true
  },
  adapter: node({
    mode: "standalone"
  })
});
 
package.json at the project root
....
  "dependencies": {
    "@astrojs/check": "^0.8.2",
    "@astrojs/node": "^8.3.2",
    "@astrojs/sitemap": "^3.1.6",
    "@astrojs/starlight": "^0.25.1",
    "@astrojs/starlight-tailwind": "^2.0.3",
    "@astrojs/tailwind": "^5.1.0",
    "astro": "^4.12.2",
    "astro-compressor": "^0.4.1",
    "firebase": "^10.12.4",
    "firebase-admin": "^12.2.0",
    "firebase-functions": "^5.0.1",
    "firebase-tools": "^13.13.3",
    "globby": "^14.0.2",
    "gsap": "^3.12.5",
    "html-minifier-terser": "^7.2.0",
    "path-to-regexp": "^7.1.0",
    "preline": "^2.3.0",
    "sharp": "^0.32.6",
    "sharp-ico": "^0.1.5",
    "tailwindcss": "^3.4.6"
  },
  "devDependencies": {
    "@tailwindcss/forms": "^0.5.7",
    "astro-vtbot": "^1.8.2",
    "prettier": "^3.3.3",
    "prettier-plugin-astro": "^0.14.1",
    "prettier-plugin-tailwindcss": "^0.6.5",
    "typescript": "^5.5.3"
  },
....
firebase.json
{
  "hosting": {
    "source": ".",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "frameworksBackend": {
      "region": "europe-west1"
    }
  },
  "functions": [
    {
      "runtime": "nodejs20",
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log",
        "*.local"
      ]
    }
  ]
}
package.json at functions folder
{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "20",
    "npm": ">=9.6.7"
  },
  "main": "index.js",
  "dependencies": {
    "firebase-admin": "^12.1.0",
    "firebase-functions": "^5.0.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^3.1.0"
  },
  "private": true
}
 
Thank you in advance; any suggestions would be welcomed.
0 1 928
1 REPLY 1

Hi @abba-n,

Welcome to Google Cloud Community!

I understand that you are experiencing issues with your Firebase deployment. According to the error message, it seems that the build process encountered an error and terminated prematurely. However, when you run it locally using firebase serve, no errors are found.

Here are some troubleshooting steps that might be helpful:

  • If you are using the Spark Plan, you cannot run server-side code in Firebase because SSR functionality requires the Blaze Plan, a paid tier. You can check the details here.
  • You can try tweaking some code in your astro.config.mjs configuration by changing the adapter mode from standalone to middleware. See a sample command below:
    import { defineConfig } from 'astro/config';
    import node from '@astrojs/node';
    
    export default defineConfig({
      output: 'server',
      adapter: node({
        mode: 'middleware',
      }),
    });
    
  • Try to initialize your Firebase by following this documentation.
  • Before deploying again, test your application locally using a different method. Testing locally with firebase serve is not recommended, as per this documentation.

By following these steps, you might gain a better understanding of the potential causes behind the errors you're encountering during your Firebase deployment.

Hope this helps.