skip to Main Content

Getting their error while running the next.js app image
:

ready – started server on 0.0.0.0:3000, url: http://localhost:3000

Error: Could not find a production build in the ‘/app/.next’ directory. Try building your app with ‘next build’ before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
at NextNodeServer.getBuildId (/app/node_modules/next/dist/server/next-server.js:137:23)
at new Server (/app/node_modules/next/dist/server/base-server.js:93:29)
at new NextNodeServer (/app/node_modules/next/dist/server/next-server.js:86:9)
at NextServer.createServer (/app/node_modules/next/dist/server/next.js:109:16)
at async /app/node_modules/next/dist/server/next.js:121:31
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: next start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-05-11T12_32_58_222Z-debug.log

Dockerfile:

FROM node:14-alpine AS deps
WORKDIR /app

COPY package.json ./
RUN npm install
COPY . .



FROM node:14-alpine AS builder
WORKDIR /app
COPY --from=deps /app ./
RUN npm build


FROM node:14-alpine AS runner
WORKDIR /app

COPY --from=builder /app/package*.json ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
RUN npm install next

EXPOSE 3000
CMD ["npm","run","start"]

Do I need to add .next in dockerignore? doing so gives me an error while building the image

3

Answers


  1. The below command solved my error

    npm run build
    
    Login or Signup to reply.
  2. This command solve your problem

    npm install

    Login or Signup to reply.
  3. One needs to build the solution before you can start it.

    Therefore add the build step immediately before the start command:

    …
    EXPOSE 3000
    CMD ["npm","run","build"]
    CMD ["npm","run","start"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search