D
Dokploy9mo ago
remib18

NextJS build issue

Hello ! I've been playing around with Dokploy to test its capabilities, and so far, I'm quite impressed. I'm currently building a test NextJS application. It was working fine after some trial and error, but suddenly, NextJS seems to be skipping the build process...
#12 [8/8] RUN pnpm run build
#12 5.335
#12 5.335 > [email protected] build /app
#12 5.335 > next build
#12 12.22
#12 13.04 ▲ Next.js 14.2.5
#12 13.04 - Environments: .env
#12 13.04
#12 13.75 Creating an optimized production build ...
#12 DONE 34.4s

#13 exporting to image
#13 exporting layers
#13 exporting layers 5.9s done
#13 writing image sha256:5e66a251337e7956ca7a956018758b154f63984fff9e9d6519d5184c83e32272 0.0s done
#13 naming to docker.io/library/website-frontend-062bee
#13 naming to docker.io/library/website-frontend-062bee 0.2s done
#13 DONE 6.4s
Docker Deployed: ✅
#12 [8/8] RUN pnpm run build
#12 5.335
#12 5.335 > [email protected] build /app
#12 5.335 > next build
#12 12.22
#12 13.04 ▲ Next.js 14.2.5
#12 13.04 - Environments: .env
#12 13.04
#12 13.75 Creating an optimized production build ...
#12 DONE 34.4s

#13 exporting to image
#13 exporting layers
#13 exporting layers 5.9s done
#13 writing image sha256:5e66a251337e7956ca7a956018758b154f63984fff9e9d6519d5184c83e32272 0.0s done
#13 naming to docker.io/library/website-frontend-062bee
#13 naming to docker.io/library/website-frontend-062bee 0.2s done
#13 DONE 6.4s
Docker Deployed: ✅
As a result, the next start command isn't working:
> next start

▲ Next.js 14.2.5
- Local: http://localhost:3000

✓ Starting...
Error: Could not find a production build in the '.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 setupFsCheck (/app/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-utils/filesystem.js:151:19)
at async initialize (/app/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:61:23)
at async Server.<anonymous> (/app/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:249:36)
 ELIFECYCLE  Command failed with exit code 1.
> next start

▲ Next.js 14.2.5
- Local: http://localhost:3000

✓ Starting...
Error: Could not find a production build in the '.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 setupFsCheck (/app/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-utils/filesystem.js:151:19)
at async initialize (/app/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:61:23)
at async Server.<anonymous> (/app/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:249:36)
 ELIFECYCLE  Command failed with exit code 1.
For reference, here's an example of the expected log output on my local machine: I've tried pruning all Docker volumes, images, containers, and build cache, but the issue persists. :/ Thanks in advance for your help!
16 Replies
remib18
remib18OP9mo ago
The logs on my local machine :
> next build

▲ Next.js 14.2.5
- Environments: .env.local

Creating an optimized production build ...
✓ Linting and checking validity of types
✓ Collecting page data
✓ Generating static pages (23/23)
✓ Collecting build traces
✓ Finalizing page optimization

Route (app) Size First Load JS
┌ ƒ / 43.8 kB 208 kB
├ ƒ /_not-found 876 B 88 kB
├ ƒ /dashboard 5.18 kB 135 kB
├ ƒ /dashboard/locations 7.74 kB 196 kB
├ ƒ /dashboard/offers 15.5 kB 189 kB
├ ƒ /dashboard/tokens-offers 7.78 kB 181 kB
├ ƒ /dashboard/users 4.24 kB 170 kB
├ ƒ /login 5.02 kB 122 kB
├ ƒ /login/via-link/[token] 0 B 0 B
├ ƒ /privacy 2.52 kB 104 kB
├ ƒ /register 5 kB 122 kB
├ ƒ /settings 5.84 kB 103 kB
├ ƒ /settings/billing 153 B 87.3 kB
├ ƒ /settings/bills 153 B 87.3 kB
├ ƒ /settings/invites 4.09 kB 118 kB
├ ƒ /settings/security 40.3 kB 158 kB
├ ƒ /settings/token-usage-historic 153 B 87.3 kB
├ ƒ /signout 0 B 0 B
├ ƒ /store 153 B 87.3 kB
└ ƒ /terms 2.52 kB 104 kB
+ First Load JS shared by all 87.1 kB
├ chunks/6842-d44ef0d85f77181c.js 31.5 kB
├ chunks/94c12b52-5a665a6f7e647ce6.js 53.6 kB
└ other shared chunks (total) 1.96 kB


ƒ Middleware 70.4 kB

ƒ (Dynamic) server-rendered on demand
> next build

▲ Next.js 14.2.5
- Environments: .env.local

Creating an optimized production build ...
✓ Linting and checking validity of types
✓ Collecting page data
✓ Generating static pages (23/23)
✓ Collecting build traces
✓ Finalizing page optimization

Route (app) Size First Load JS
┌ ƒ / 43.8 kB 208 kB
├ ƒ /_not-found 876 B 88 kB
├ ƒ /dashboard 5.18 kB 135 kB
├ ƒ /dashboard/locations 7.74 kB 196 kB
├ ƒ /dashboard/offers 15.5 kB 189 kB
├ ƒ /dashboard/tokens-offers 7.78 kB 181 kB
├ ƒ /dashboard/users 4.24 kB 170 kB
├ ƒ /login 5.02 kB 122 kB
├ ƒ /login/via-link/[token] 0 B 0 B
├ ƒ /privacy 2.52 kB 104 kB
├ ƒ /register 5 kB 122 kB
├ ƒ /settings 5.84 kB 103 kB
├ ƒ /settings/billing 153 B 87.3 kB
├ ƒ /settings/bills 153 B 87.3 kB
├ ƒ /settings/invites 4.09 kB 118 kB
├ ƒ /settings/security 40.3 kB 158 kB
├ ƒ /settings/token-usage-historic 153 B 87.3 kB
├ ƒ /signout 0 B 0 B
├ ƒ /store 153 B 87.3 kB
└ ƒ /terms 2.52 kB 104 kB
+ First Load JS shared by all 87.1 kB
├ chunks/6842-d44ef0d85f77181c.js 31.5 kB
├ chunks/94c12b52-5a665a6f7e647ce6.js 53.6 kB
└ other shared chunks (total) 1.96 kB


ƒ Middleware 70.4 kB

ƒ (Dynamic) server-rendered on demand
Siumauricio
Siumauricio9mo ago
Are you using nixpacks?
remib18
remib18OP9mo ago
no i'm using a docker file. here's the content of the file :
FROM node:20-alpine

RUN apk add --no-cache python3 make g++ libpq-dev
RUN npm install -g pnpm

ENV NODE_ENV=production

WORKDIR /app

COPY package*.json /app

RUN pnpm i

COPY . /app

EXPOSE 3000

RUN pnpm run build

CMD ["pnpm", "run", "start"]
FROM node:20-alpine

RUN apk add --no-cache python3 make g++ libpq-dev
RUN npm install -g pnpm

ENV NODE_ENV=production

WORKDIR /app

COPY package*.json /app

RUN pnpm i

COPY . /app

EXPOSE 3000

RUN pnpm run build

CMD ["pnpm", "run", "start"]
Vlad
Vlad9mo ago
Well, if I were you, I would use the dockerfile made by nextjs devs
Vlad
Vlad9mo ago
GitHub
next.js/examples/with-docker/Dockerfile at canary · vercel/next.js
The React Framework. Contribute to vercel/next.js development by creating an account on GitHub.
Vlad
Vlad9mo ago
Or you can simply use nixpacks, it will automatically detect that you're using nextjs and deploy it as a nextjs app as if you deployed on vercel
remib18
remib18OP9mo ago
i tryied using nixpacks as you suggested but i got the following error :
#9 [stage-0 5/10] COPY . /app/.
#9 DONE 1.3s

#10 [stage-0 6/10] RUN --mount=type=cache,id=6DEYbTUNBTA-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i --frozen-lockfile
#10 4.273  WARN  Ignoring not compatible lockfile at /app/pnpm-lock.yaml
#10 4.284  ERR_PNPM_NO_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absent
#10 4.284
#10 4.284 Note that in CI environments this setting is true by default. If you still need to run install in such cases, use "pnpm install --no-frozen-lockfile"
#10 ERROR: process "/bin/bash -ol pipefail -c pnpm i --frozen-lockfile" did not complete successfully: exit code: 1
------
> [stage-0 6/10] RUN --mount=type=cache,id=6DEYbTUNBTA-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i --frozen-lockfile:
4.273  WARN  Ignoring not compatible lockfile at /app/pnpm-lock.yaml
4.284  ERR_PNPM_NO_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absent
4.284
4.284 Note that in CI environments this setting is true by default. If you still need to run install in such cases, use "pnpm install --no-frozen-lockfile"
------
Dockerfile:20
--------------------
18 | ENV NIXPACKS_PATH /app/node_modules/.bin:$NIXPACKS_PATH
19 | COPY . /app/.
20 | >>> RUN --mount=type=cache,id=6DEYbTUNBTA-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i --frozen-lockfile
21 |
22 | # build phase
#9 [stage-0 5/10] COPY . /app/.
#9 DONE 1.3s

#10 [stage-0 6/10] RUN --mount=type=cache,id=6DEYbTUNBTA-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i --frozen-lockfile
#10 4.273  WARN  Ignoring not compatible lockfile at /app/pnpm-lock.yaml
#10 4.284  ERR_PNPM_NO_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absent
#10 4.284
#10 4.284 Note that in CI environments this setting is true by default. If you still need to run install in such cases, use "pnpm install --no-frozen-lockfile"
#10 ERROR: process "/bin/bash -ol pipefail -c pnpm i --frozen-lockfile" did not complete successfully: exit code: 1
------
> [stage-0 6/10] RUN --mount=type=cache,id=6DEYbTUNBTA-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i --frozen-lockfile:
4.273  WARN  Ignoring not compatible lockfile at /app/pnpm-lock.yaml
4.284  ERR_PNPM_NO_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absent
4.284
4.284 Note that in CI environments this setting is true by default. If you still need to run install in such cases, use "pnpm install --no-frozen-lockfile"
------
Dockerfile:20
--------------------
18 | ENV NIXPACKS_PATH /app/node_modules/.bin:$NIXPACKS_PATH
19 | COPY . /app/.
20 | >>> RUN --mount=type=cache,id=6DEYbTUNBTA-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i --frozen-lockfile
21 |
22 | # build phase
--------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c pnpm i --frozen-lockfile" did not complete successfully: exit code: 1
Error: Docker build failed
Error response from daemon: No such container: urbansecrets-website-frontend-062bee-XfZpWrgbaA
Error ❌
--------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c pnpm i --frozen-lockfile" did not complete successfully: exit code: 1
Error: Docker build failed
Error response from daemon: No such container: urbansecrets-website-frontend-062bee-XfZpWrgbaA
Error ❌
Vlad
Vlad9mo ago
Are you sure pnpm-lock.yaml exists in your repo?
remib18
remib18OP9mo ago
yes ^^ i've checked on github in the case i've misconfigured something and he file is there
remib18
remib18OP9mo ago
i've fixed the problem by specifying the exact version of pnpm in the package.json file I've ran into another issue where i need some additional packages (python3 make g++ libpq-dev) but i didn't found in the documentation if it is possible to pass arguments to nixpacks like showed here : https://nixpacks.com/docs/guides/configuring-builds
Configuring Builds | Nixpacks
App source + Nix packages + Docker = Image
Siumauricio
Siumauricio9mo ago
In my case for docs and website I use a dockerfile https://github.com/Dokploy/dokploy/blob/canary/Dockerfile.website for nextjs app
GitHub
dokploy/Dockerfile.website at canary · Dokploy/dokploy
Open Source Alternative to Vercel, Netlify and Heroku. - Dokploy/dokploy
Siumauricio
Siumauricio9mo ago
if you want to specify custom arguments create a nixpacks.toml and automatically nixpacks will detect it
Sang Dang
Sang Dang9mo ago
If I remember correctly I faced similar situation, with pnpm 9 and nixpacks. I have to stay with pnpm 8 to avoid it. I will try to find the github issue.
Sang Dang
Sang Dang9mo ago
GitHub
Support for pnpm v9 · Issue #1091 · railwayapp/nixpacks
Is there an existing issue for this? I have searched the existing issues Describe the bug When upgrading our service to use pnpm v9, nixpacks is still using pnpm v8 package.json "engines"...
TheLetslook
TheLetslook9mo ago
You can use a workaround by creating a nixpacks.toml file in the root directory of your project with this content:
providers = ["node"]

[phases.install]
cmds = ["npm install -g corepack", "corepack enable", "corepack prepare [email protected] --activate", "pnpm install"]
providers = ["node"]

[phases.install]
cmds = ["npm install -g corepack", "corepack enable", "corepack prepare [email protected] --activate", "pnpm install"]

Did you find this page helpful?