I'm currently working on a Next.js project that is deployed using Firebase App Hosting (not Firebase Hosting). Recently, I integrated Cloud Functions into my setup by uncommenting the example function:
import {onRequest} from "firebase-functions/v2/https";
import * as logger from "firebase-functions/logger";
export const helloWorld = onRequest((request, response) => {
logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});
When deploying just the Cloud Functions with the command firebase deploy --only functions
, everything works perfectly. However, issues arise when deploying the entire application with App Hosting. An error occurs pointing to missing dependencies, indicating a potential problem in how App Hosting manages dependencies for both the app and the Cloud Functions.
Check out the Cloud build error logs here
Here's an overview of my project structure:
- The web app is deployed using App Hosting for Next.js.
- Firebase Functions are deployed with firebase-functions using TypeScript.
- Both the app and functions have separate package.json files, ensuring that functions use their own dependencies within the functions/ directory.
/project_name
├── /app
├── /components
├── /functions
│ ├── /lib
│ ├── /src
│ │ └── index.ts
│ ├── package.json
│ ├── tsconfig.json
│ └── .eslintrc.js
├── /public
├── .firebaserc
├── firebase.json
├── apphosting.yaml
├── .gitignore
├── package.json
├── package-lock.json
├── next.config.js
├── tsconfig.json
├── next.config.mjs
The main issue lies in the full app deployment causing errors related to missing dependencies while Cloud Functions deployment alone works seamlessly. I suspect a conflict in dependency management between the app and the functions during App Hosting project builds.
- Confirmed that the functions directory has its own package.json file with required dependencies listed.
- Ensured the app’s package.json only includes dependencies essential for the Next.js build.
- Validated the correct configuration of environment variables in apphosting.yaml.
My expectation was that the successful independent deployment of functions would also work smoothly when deployed through app hosting.
Looking for assistance with:
- Identifying any known challenges with Firebase App Hosting when deploying a Next.js app alongside Cloud Functions.
- Any specific Firebase guidelines to ensure the proper handling of dependencies for the app and Cloud Functions within the App Hosting environment?