NuxtN
Nuxt10mo ago
4 replies
Viridian

Cannot find 'nuxt.mjs' during build in Dockerfile

Hey all,

I'm trying to build my Nuxt application via Docker, but my Dockerfile is giving me the following error:

0.472 > nuxt-app@ build /app
0.472 > nuxt build
0.472
0.489 node:internal/modules/cjs/loader:1228
0.489   throw err;
0.489   ^
0.489
0.489 Error: Cannot find module '/app/node_modules/nuxt/bin/nuxt.mjs'
0.489     at Function._resolveFilename (node:internal/modules/cjs/loader:1225:15)
0.489     at Function._load (node:internal/modules/cjs/loader:1055:27)
0.489     at TracingChannel.traceSync (node:diagnostics_channel:322:14)
0.489     at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
0.489     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
0.489     at node:internal/main/run_main_module:36:49 {
0.489   code: 'MODULE_NOT_FOUND',
0.489   requireStack: []
0.489 }
0.489
0.489 Node.js v22.14.0
0.499  ELIFECYCLE  Command failed with exit code 1.


This is my Dockerfile:

ARG NODE_VERSION=22.14.0

FROM node:${NODE_VERSION}-slim AS build

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app

COPY ./package.json /app/
COPY ./pnpm-lock.yaml /app/

RUN pnpm install --shamefully-hoist

COPY . ./

RUN pnpm run build

FROM node:${NODE_VERSION}-slim

WORKDIR /app

COPY --from=build /app/.output ./

ENV HOST=0.0.0.0 NODE_ENV=production
ENV NODE_ENV=production

EXPOSE 3000

CMD ["node", "/app/server/index.mjs"]


Building locally seems to work just fine, so I'm not sure what's causing this issue. Any help would be appreciated!
Was this page helpful?