Challenges with Firebase App Hosting and Cloud Functions Dependencies in Deploying Next.js Application

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?

Answer №1

After some troubleshooting, I managed to resolve this issue by removing the functions folder from ./tsconfig.json and then deploying the functions separately using the command firebase deploy --only functions:

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules", "./functions"]
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leverage Firebase and AngularJS to manage the process of verifying email

Currently, my web app utilizes Firebase and AngularJS. I have a factory that is used across all modules in my app: .factory('Auth', ["$firebaseAuth", function($firebaseAuth) { return $firebaseAuth(); } ]); Ensuring authentication ...

Monitoring controller variables in Angular 4

Imagine having a piece of old code that you don't want to modify. There are three server calls involved in fetching data, and after all three methods succeed, you need to execute some additional code. I introduced a variable and now want to monitor it ...

"Challenges with conditional exports and bundle size discrepancies arise when utilizing TurboRepo for a monorepo structure with a Next.js application and buildable

Trying to set up a JS/TS monorepo using Turborepo: . └── root ├── apps │ ├── first-app (next.js app) │ └── second-app (next.js app) ├── configs (ts, tsup) └── packages └── ui (re ...

What is the best way to efficiently conduct multiple reads in Firebase Cloud Firestore?

Within Firebase's Cloud Firestore database, I have a collection with various subcollections structured as follows: myCollection doc1 statistics doc1 doc2 doc3 doc2 statistics doc ...

Utilizing a map in conjunction with template literal types results in an error being thrown

I am currently working on implementing the documentation provided here. This is the code snippet I have: enum InputFieldName { ReactionsCheckbox = 'reactionsEnabled', SettingsCheckbox = 'settingsEnabled', } type PropEventSource ...

Utilize Typescript to expand the functionality of the Express Request object

Is there a way to add a custom property to the request object in Express middleware using TypeScript without resorting to bracket notation? I am struggling to find a solution that satisfies this requirement. I would ideally like to achieve something like ...

Using Angular to include more than two parameters in an HTTP GET request

Currently, I am developing an application that requires downloading a file upon clicking a button within a template. The screen displays multiple files, each with its own corresponding button. I need to send the index number of the array to Angular and pas ...

What is the process for obtaining a flattened tuple type from a tuple comprised of nested tuples?

Suppose I have a tuple comprised of additional tuples: type Data = [[3,5,7], [4,9], [0,1,10,9]]; I am looking to develop a utility type called Merge<T> in such a way that Merge<Data> outputs: type MergedData = Merge<Data>; // type Merged ...

Error: Attempting to access property 'prod_id' of an undefined variable

Hi there, I'm encountering an issue and would appreciate some assistance. I need to test a function as shown in the code snippet below: populateForm() { this.activatedRoute.params.subscribe( params => { this.ws.getbyid(params[&a ...

The object prototype can only be an instance of an Object or null; any other value will

While attempting to create a codesandbox in order to replicate a bug, I encountered an additional issue. You can view my codesandbox here: https://codesandbox.io/s/vue-typescript-example-o7xsv The error message states: Object prototype may only be an ...

extracting the HTML content from JavaScript and saving it into a standalone file

update When I click a link, a popup opens and I see all this HTML. The smile method is called when I click the link, and we append HTML in that method so that we can see it when the popup is opened. I moved it to a separate file something.component.html, ...

What are the differences in impact between utilizing 2-way binding with signals versus plain properties in Angular?

In the documentation, it is mentioned that a 2-way binding can be created using plain properties, as well as using signals. The documentation does not elaborate on the advantages or disadvantages of each option. It seems logical that if I want the parent ...

We're sorry, but the system could not locate the module you are trying to access. The error message states: "Cannot find

I am working on my Next.js application and want to utilize the Image feature. My approach for importing the necessary dependencies is as follows: import React from "react"; import Link from "next/link"; import Image from "next/ima ...

Tips for retrieving the slug value in getStaticProps for invoking the API with the slug as a parameter

Content on the Page: import { useRouter } from "next/router"; export default function Daily({ data }) { let router = useRouter() const { slug } = router.query; return slug; } And display on the page 60d6180ea9284106a4fd8441 ...

Angular: How can I apply animation to rotate an image within a component?

Within my map application, I have implemented a component called compass component. I am seeking a way to programmatically rotate this compass with animation as the map is rotated. The solution involves utilizing angular animation. To achieve this functio ...

A TypeScript interface that corresponds to a function and its input parameters

I have multiple functions with various argument types: function foo(a: number) {...} function bar(a: string) {...} ... To tackle this, I want to define a TypeScript interface (or type) that can handle these scenarios: interface MyInterface { method: ty ...

Introducing a detailed model showcasing information sourced from an array of objects within Angular 14

I'm struggling to showcase detailed models for various elements in my project. In essence, I have a collection of cards that hold diverse information data. The objective is simple: upon clicking a button to reveal more details about a selected card, a ...

Can we confidently disregard React's caution regarding using the useState hook conditionally if only the parameter changes based on a condition?

In my React app, I am working on creating a calendar date selection function component to assign days to schedules. My goal is to pre-populate the calendar with existing data so users can modify it as needed. Here is what I have implemented so far: const ...

The initial rendering of the NextJs 13 application is experiencing significant sluggishness when deployed on an EC2

After deploying my NextJS 13.4 app on an AWS EC2 instance with 2 GB of RAM, I noticed that the initial load time is quite slow, taking around 20 seconds to load for the first time. The development mode in NextJS builds and displays the result, which may co ...

Implement the CSS styles from the Parent Component into the Child Component using Angular 6

Is there a way to apply CSS from the Parent Component to style the child component in Angular 6? Please advise on how to approach this issue. How can we inherit the css styles from the Parent Component? <parent> <child> <p>hello ...