Skip to content

Deployment Issue – "Could not find a production build in the '.next' directory" #8327

Closed
@Buenaventura-Celine

Description

@Buenaventura-Celine

[REQUIRED] Environment info

firebase-tools: 12.5.0

Platform: MacOS
Next JS: 14.2.24

[REQUIRED] Test case

Hello,

I am deploying my Next.js app using Firebase. My project consists of a Next.js frontend with Firebase as the backend, which is why I chose Firebase for deployment. The app relies on Server-Side Rendering (SSR) and uses functions like getServerSideProps.

However, after deployment, the website displays the following error:

Error during Next.js app preparation: Could not find a production build in the '.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id

It seems like Firebase is not detecting or using the .next directory properly. I have already ensured that I ran next build before deploying.

[REQUIRED] Steps I did before deployment

  1. In the terminal, I ran the following:
  2. firebase experiments:enable webframeworks
  3. Created firebase functions to serve dynamic pages
import {default as next} from "next";
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";

admin.initializeApp();

const dev = process.env.NODE_ENV !== "production";
const app = next({dev});
const handle = app.getRequestHandler();

export const nextjs = functions.https.onRequest((req, res) => {
  app
    .prepare()
    .then(() => {
      handle(req, res);
    })
    .catch((err: Error) => {
      res
        .status(500)
        .send("Error during Next.js app preparation: " + err.message);
    });
});

This is also my firebase.json

 "hosting": {
    "rewrites": [
      {
        "source": "/api/**",
        "function": "nextjs"
      },
      {
        "source": "/**",
        "function": "nextjs"
      }
    ],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "frameworksBackend": {
      "region": "us-central1"
    }
  },
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint",
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    }
  ]

Then I run the npm run build, for me to have the .next folder then after that firebase deploy. Am I missing something?

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions