Next.js Discord

Discord Forum

Docker: Failed to collect page data

Unanswered
remib18 posted this in #help-forum
Open in Discord
Hey ! I'm trying to selfhost a NextJS app.
The build process works well on my Mac but whenever i try to build it through Docker, i encounter the following error :
 > [builder 5/5] RUN pnpm run build:
36.90   code: 'ERR_INVALID_ARG_TYPE'
36.90 }
36.92 
36.92 > Build error occurred
36.92 Error: Failed to collect page data for /login/via-link/[token]
36.92     at /app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/build/utils.js:1268:15
36.92     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
36.92   type: 'Error'
36.92 }
36.94  ELIFECYCLE  Command failed with exit code 1.
------
Dockerfile:31
--------------------
  29 |     # ENV NEXT_TELEMETRY_DISABLED=1
  30 |     
  31 | >>> RUN pnpm run build
  32 |     
  33 |     # Production image, copy all the files and run next
--------------------
ERROR: failed to solve: process "/bin/sh -c pnpm run build" did not complete successfully: exit code: 1

2 Replies

Here's the page concerned :
'use server';

import {getMagicLinkByToken} from "@/controllers/magic-links";
import {auth} from "@/lib/auth";
import {createJWTs} from "@/lib/auth/jwt-utils";
import {getUserByEmail} from "@/controllers/users";
import {notFound, redirect} from "next/navigation";



export default async function LoginViaLinkPage(
    { params }: { params: { token: string } }
) {
    const session = await auth()

    if (session && session.authProcess.status === 'complete') {
        redirect('/')
    }

    const res = await getMagicLinkByToken(params.token);

    if (!res.success) {
        notFound()
    }

    let email: string;
    const { data } = res;

    if (session?.authProcess.magicLink) {
        email = session.authProcess.magicLink.email;

        if (data.email !== email) {
            notFound()
        }
    }

    const userRes = await getUserByEmail(data.email);

    if (!userRes.success) {
        notFound()
    }

    await createJWTs({
        user: userRes.data,
        authProcess: {
            status: 'complete',
            stage: 'verify',
            method: 'magic-link'
        }
    })

    redirect('/');

}
And my dockerFile :
FROM node:22-alpine AS base

# Install dependencies only when needed
FROM base AS deps

# Install the necessary dependencies.
RUN apk add --no-cache libc6-compat python3 make g++ libpq-dev
WORKDIR /app

# Install pnpm
RUN corepack enable pnpm

# Install dependencies
COPY package.json pnpm-lock.yaml ./
RUN pnpm i --frozen-lockfile


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN corepack enable pnpm

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED=1

RUN pnpm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV HOSTNAME=0.0.0.0
ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]