skip to Main Content

I have a Next.js v13.4 application with Prisma v5.2.0 and I am experiencing a build error while trying to dockerize the application. The build process unexpectedly exits with an error during static page generation. Here’s a snippet from the Docker build log:

Static worker unexpectedly exited with code: null and signal: SIGTERM
Error: Static page generation for / is still timing out after 3 attempts.

This issue seems to be linked to the src/app/page.js file. When the following piece of code:

// page.js
import SortingHat from "@/components/SortingHat";
import { prisma } from "@/lib/db";
import { redirect } from "next/navigation";

export default async function Home() {
  const setup = await prisma.User.findMany();
  if (setup.length > 0) {
    return <SortingHat />;
  } else {
    redirect(`/setup`);
  }
}

is modified to:

// page.js
Copy code
import SortingHat from "@/components/SortingHat";

export default async function Home() {
  return <SortingHat />;
}

the Docker build completes successfully.

As a workaround, I moved the redirect logic into the SortingHat component, but I would like to understand the cause of the original problem. You can view my Dockerfile here.

Additional Info:

Node Version: 18-alpine3.16
Prisma Version: v5.2.0
Using SQLite as a database.
I have tried updating Prisma to the latest version v5.4.2 but still experience the same issue.
Can someone help diagnose why the static worker unexpectedly exits during the build process and how to fix this issue without moving the redirect logic?

If you have more questions or I have omitted important information please let me know.

All I could do was remove pieces of code which is how I solved the problem but I would really like to know why it didn’t work in the first place.
edit: I also tried to raise the timeout as such

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverActions: true,
  },
  staticPageGenerationTimeout: 1000,
}

module.exports = nextConfig

2

Answers


  1. Chosen as BEST ANSWER

    RESOLVED: So the problem ended up being that next was building page.js as static. solution: export const dynamic = 'force-dynamic' at the top level of the page


  2. The issue might stem from an incorrect Prisma database connection setup during the Docker build. To resolve this, ensure the accuracy of your Prisma configuration and confirm that the database is reachable as the application builds within the Docker container. Additionally, verify that the Docker network is properly configured and the database container is up and running before the Next.js build process begins. Furthermore, check the resource allocation for the Docker container, including CPU and memory settings, to make certain they are sufficient for the build. You can fine-tune these resource parameters in your Docker Compose or Dockerfile. You’ve also attempted to extend the staticPageGenerationTimeout, but it’s crucial to carefully assess the duration necessary for fetching data from Prisma during the build process to set an appropriate value.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search