#"Collecting page data for /page is still timing out after 2 attempts" on build

3 messages · Page 1 of 1 (latest)

surreal spear
#

When I run an npm run build for prod, it seems to be trying to connect to redis but it can't so it just times out and the build fails after a few minutes. I recently added redis, but I didn't have this issue with my database in the past. Tried looking around online but I can't find anyone else with this issue and I'm not sure what to do about it at this point. Would love some help.

I am running next 14.2.13 with the app directory. My build process is done via docker:

FROM node:22 as base
WORKDIR /app

EXPOSE 3000

ENV PORT 3000

COPY package.json package-lock.json ./

RUN npm install --frozen-lockfile
RUN apt-get update && apt-get install -y imagemagick

COPY . .
RUN if [ -d /app/.next/ ]; then chown -R 1000:1000 /app/.next/; fi

FROM base as prod
RUN npx prisma generate && npm run build
USER 1000
CMD ["npm", "run", "start:migrate:prod"]

FROM base as dev
USER 1000
CMD ["npm", "run", "dev"]
```and my app is run with docker compose:
```yml
services:
  app:
    # volumes:
    #   - ./:/app
    build:
      context: ./
      dockerfile: ./Dockerfile
      target: prod
    container_name: app
    user: "1000"
    ports:
      - "3000:3000"
      - "9230:9229"
    environment:
      - NODE_ENV=production
      - DEBUG=engine
    env_file:
      - ./.env
    restart: unless-stopped

  db:
    image: postgis/postgis:16-3.4
    container_name: app-db
    restart: always
    env_file:
      - ./.env
    environment:
      POSTGRES_DB: default
    user: "1000"
    volumes:
      - ./db:/var/lib/postgresql/data

  redis:
    image: redis:alpine
    container_name: app-redis
    restart: always
```And I'm just running `docker compose build`.

Here is what I have for my redis.ts file:
```ts
import { createClient } from 'redis';

export const redis = await createClient({
  url: process.env.REDIS_URL,
})
  .on('error', (err) => console.error(err))
  .connect();
vale sierraBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

surreal spear
#

cont. here since I hit the character limit above. Similar to my redis implementation, here is my database connection. I do not have issues with npm run build when I have only the database. Once I added redis that's when I started running into this issue. I use the same process of grabbing the connection variables from the env, and everything works perfectly fine on dev so I know all the env vars are configured correctly.

import { PrismaClient } from '@prisma/client';

const options = {
  log: [
    {
      emit: 'event',
      level: 'query',
    },
  ],
} as any;
const prismaClientSingleton = () => new PrismaClient(
  process.env.NODE_ENV === 'development' ? options : undefined,
);

declare const globalThis: {
  prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;

// eslint-disable-next-line import/no-mutable-exports
let prisma: PrismaClient;

// Prevent nextjs from trying to load prisma in the browser
if (typeof window === 'undefined') {
  if (process.env.NODE_ENV === 'production') {
    prisma = prismaClientSingleton();
  } else {
    if (!globalThis.prismaGlobal) {
      globalThis.prismaGlobal = prismaClientSingleton();

      // @ts-ignore
      globalThis.prismaGlobal.$on('query', (e: any) => {
        console.log(`Query: ${e.query} ${e.params}`);
        console.log(`Duration: ${e.duration}ms`);
      });
    }
    prisma = globalThis.prismaGlobal;
  }
} else {
  prisma = {} as PrismaClient;
}

export default prisma;