Next.js Discord

Discord Forum

next build : docker build image [Couldn't find any `pages` or `app` directory]

Answered
French Angora posted this in #help-forum
Open in Discord
French AngoraOP
please help me to find out this error

i'm using docker-compose in my next.js app
yarn dev in dockerfile works well

while building image
yarn build no works it gets this error
Please help me😀😭

> Build error occurred
Error: > Couldn't find any `pages` or `app` directory. Please create one under the project root
    at findPagesDir (/app/node_modules/next/dist/lib/find-pages-dir.js:54:15)
    at /app/node_modules/next/dist/build/index.js:195:75
    at async Span.traceAsyncFn (/app/node_modules/next/dist/trace/trace.js:103:20)
    at async build (/app/node_modules/next/dist/build/index.js:148:29)
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.


docker-compose yml file

version: '3.8'
services:
  client:
    container_name: next-app
    build:
      context: ./client
      target: prod
    ports:
      - '3000:3000'


this is my dockerfile

FROM node:18-alpine as prod
WORKDIR /app
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN yarn install 
RUN yarn build
COPY . .
EXPOSE 3000
CMD ["yarn", "start"]
Answered by @ts-ignore
move yarn build after COPY . .
View full answer

10 Replies

Answer
@@ts-ignore move `yarn build` after `COPY . .`
French AngoraOP
oh yes !
it works well 😀

but why this works?
@French Angora oh yes ! it works well 😀 but why this works?
the build command needs the source code which is only available once you COPY
French AngoraOP
oh yes thanks a log
@French Angora oh yes thanks a log
np mark this as solved
French AngoraOP
actually im finding how to mark as answered 🥲
@French Angora actually im finding how to mark as answered 🥲
follow the instructions in the embed
French AngoraOP
😭
thanks :)
French AngoraOP
oh i did thanks~!