GoogleContainerTools / distroless

đŸ„‘ Language focused docker images, minus the operating system.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nuxt.js throws Error: Cannot find module '/app/node'

domints opened this issue · comments

Describe the bug
I try to create smallest possible container with Nuxt.js app, right after creating it from template. App is properly working with node:20.12.0-alpine3.19, node:18.20.0-bullseye-slim images and some more official images.
The same problem happens to all node images in distroless repo.

To Reproduce

  • run npx nuxi@latest init test-app to create app
  • cd test-app
  • npm run build
  • create dockerfile:
FROM gcr.io/distroless/nodejs20-debian12
ARG PORT=3000
ENV PORT=$PORT
ENV NODE_ENV=production

WORKDIR /src

COPY ./.output /src/.output
# Optional, only needed if you rely on unbundled dependencies
# COPY ./node_modules /srcƛ/node_modules

EXPOSE $PORT/tcp
CMD [ "node", ".output/server/index.mjs" ]
  • build image with docker build -t test-app:ssr-test ./
  • try running the image (I use Docker Desktop for Mac)
  • observe error in log output

Expected behavior
Application should be running, so:

  • you should see Listening on http://[::]:3000 message in console
  • if you bound port 3000 to something on your local machine you should be able to navigate to it and see "Welcome to Nuxt!" page

Console Output

2024-04-02 18:06:27 node:internal/modules/cjs/loader:1146
2024-04-02 18:06:27   throw err;
2024-04-02 18:06:27   ^
2024-04-02 18:06:27 
2024-04-02 18:06:27 Error: Cannot find module '/src/node'
2024-04-02 18:06:27     at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
2024-04-02 18:06:27     at Module._load (node:internal/modules/cjs/loader:984:27)
2024-04-02 18:06:27     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
2024-04-02 18:06:27     at node:internal/main/run_main_module:28:49 {
2024-04-02 18:06:27   code: 'MODULE_NOT_FOUND',
2024-04-02 18:06:27   requireStack: []
2024-04-02 18:06:27 }
2024-04-02 18:06:27 
2024-04-02 18:06:27 Node.js v20.12.0
commented

honestly, I don't know enough about node to help here and am lacking the skills to debug this. We can wait for someone else to find it here, but I think you're better off asking on stackoverflow or a nodejs help forum.

I'm asking here, because I am pretty certain it's something with how distroless images are built that breaks it, which makes it somehow incomplete/broken node images :)

I'd suggest changing CMD [ "node", ".output/server/index.mjs" ] to CMD [ ".output/server/index.mjs" ].

Oooooooh...

It's me missing it in the docs because I didn't expect this to work different way than other node-specific images.

Thanks for pointing out, @aaharu :) Now it works :)