Issue when deploying node app using docker

I'm having issues when I'm trying to deploy a node app with docker, when I build and run the image locally it runs fine but on railway it shows me the build the built node file not found. Also, this is something that is fairly recent and my docker config file hasn't changed so not sure why this might be happening. Help appreciated, thanks!
Solution:
ah thanks, just found out the cause of the issue. It was a change that was pushed yesterday that resulted in dist folder not being generated in CI builds which is why it worked locally but not when it was deployed via CI.
P
Percy18d ago
Project ID: 033f39f1-9797-405f-88f8-343ca4ac4254
J
Jay18d ago
033f39f1-9797-405f-88f8-343ca4ac4254 For some context, the build succeeds but when the cmd command is ran is when the error is thrown and the healthcheck fails, causing the deployment to fail.
B
Brody18d ago
Please send the dockerfile and the error that is thrown
J
Jay18d ago
Hey, thanks for the quick reply! Is there a private portal that I can send it through? nvm, sorry I just realized I don't have any sensitive info in the docker file so here it goes
FROM node:20-alpine AS alpine
RUN apk add --no-cache libc6-compat
RUN apk update

# Setup pnpm and turbo on the alpine base
FROM alpine as base
RUN npm install pnpm turbo --global
RUN pnpm config set store-dir ~/.pnpm-store

# Prune projects
FROM base AS pruner

ARG PROJECT="@repo/api"

WORKDIR /app
COPY . .
RUN turbo prune --scope=${PROJECT} --docker

# Build the project
FROM base AS builder
ARG PROJECT="@repo/api"

WORKDIR /app

# Copy lockfile and package.json's of isolated subworkspace
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
COPY --from=pruner /app/out/json/ .

# First install the dependencies (as they change less often)
RUN pnpm install --frozen-lockfile

# Copy source code of isolated subworkspace
COPY --from=pruner /app/out/full/ .

# Env vars required to build the project
ARG DATABASE_URL
ARG SOME_OTHER_KEY

RUN turbo build --filter=${PROJECT}
RUN rm -rf ./node_modules
RUN pnpm install --prod --frozen-lockfile

# Final image
FROM alpine AS runner

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nodejs
USER nodejs

WORKDIR /app
COPY --from=builder --chown=nodejs:nodejs /app .
WORKDIR /app/apps/api

ARG PORT=8080
ENV PORT=${PORT}

CMD ["node","dist/index.js"]
FROM node:20-alpine AS alpine
RUN apk add --no-cache libc6-compat
RUN apk update

# Setup pnpm and turbo on the alpine base
FROM alpine as base
RUN npm install pnpm turbo --global
RUN pnpm config set store-dir ~/.pnpm-store

# Prune projects
FROM base AS pruner

ARG PROJECT="@repo/api"

WORKDIR /app
COPY . .
RUN turbo prune --scope=${PROJECT} --docker

# Build the project
FROM base AS builder
ARG PROJECT="@repo/api"

WORKDIR /app

# Copy lockfile and package.json's of isolated subworkspace
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
COPY --from=pruner /app/out/json/ .

# First install the dependencies (as they change less often)
RUN pnpm install --frozen-lockfile

# Copy source code of isolated subworkspace
COPY --from=pruner /app/out/full/ .

# Env vars required to build the project
ARG DATABASE_URL
ARG SOME_OTHER_KEY

RUN turbo build --filter=${PROJECT}
RUN rm -rf ./node_modules
RUN pnpm install --prod --frozen-lockfile

# Final image
FROM alpine AS runner

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nodejs
USER nodejs

WORKDIR /app
COPY --from=builder --chown=nodejs:nodejs /app .
WORKDIR /app/apps/api

ARG PORT=8080
ENV PORT=${PORT}

CMD ["node","dist/index.js"]
And here are the logs:
node:internal/modules/cjs/loader:1146

throw err;

^

Error: Cannot find module '/app/apps/api/dist/index.js'

at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)

at Module._load (node:internal/modules/cjs/loader:984:27)

at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)

at node:internal/main/run_main_module:28:49 {

code: 'MODULE_NOT_FOUND',

requireStack: []

}
node:internal/modules/cjs/loader:1146

throw err;

^

Error: Cannot find module '/app/apps/api/dist/index.js'

at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)

at Module._load (node:internal/modules/cjs/loader:984:27)

at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)

at node:internal/main/run_main_module:28:49 {

code: 'MODULE_NOT_FOUND',

requireStack: []

}
B
Brody18d ago
just realized I don't have any sensitive info in the docker file
i would sure hope so 😆 can you try removing the WORKDIR /app/apps/api line
J
Jay18d ago
sure, I'll try it and be back in a bit! appreciate the quick responses! okay, so it just finished a deployment but I'm still getting the same error. I updated the dockerfile to remove WORKDIR /app/apps/api and updated the CMD command to run node apps/api/dist/index.js but I'm still seeing the same error.
B
Brody18d ago
are you sure the dist folder is going to end up in /app/apps/api?
J
Jay18d ago
mhm, yeah I checked the built image locally and the index.js file to be run is inside the /app/apps/api/dist directory.
B
Brody18d ago
chuck in some ls commands and see what that prints on railway?
J
Jay18d ago
I'm sorry but I don't know how to do that in railway? is there an article i can follow to see how to do so?
B
Brody18d ago
RUN ls -l
J
Jay18d ago
ah, gotcha in the docker image, right?
B
Brody18d ago
Dockerfile
J
Jay18d ago
yes, got it thanks! will try and get back with what shows up
B
Brody18d ago
sounds good
Solution
J
Jay18d ago
ah thanks, just found out the cause of the issue. It was a change that was pushed yesterday that resulted in dist folder not being generated in CI builds which is why it worked locally but not when it was deployed via CI.
B
Brody18d ago
awesome
J
Jay18d ago
Thanks again for all the help, appreciate it! Kinda feel bad that it is a simple fix and I took up a decent bit of your time.
B
Brody18d ago
no worries at all
Want results from more Discord servers?
Add your server
More Posts
FastAPI service health-check fails in IPV6I'm running a fastAPI service in railway. I setup a `/healthcheck` endpoint. It worked well when I eServer Response too slowI have Django, React application live on railway. I'm using Hobby plan. whenever I click through pDown only in DubaiHi Railway, Starting around 7.30 PM UTC +4, we can’t access our production instances. The URL is zeApplying chance is persistingI have this popup constantly appearing, even though nothing is being updated / changed. Anyway to geMySQL Memory UsageHey there, we just migrated to Railway and in the last 24h I saw that the memory usage is consistentRailway crashed after errors on trycatch?Is there any parameter to change in Railway so that it doesn't crash? because I'm using a trycatch tRailway having trouble connecting to local db upon deploymentHi. I recently deployed my node.js app on Railway and found out that during startup of my node.js apRedeploying service doesnt use updated Source Repo URLHi im new to railway so maybe this is a misunderstanding. I have started a project using a template rust deploy uses 10x more ram than local devhey guys, i have a rust api that is using 4-8gb of ram suddenly, now for rust that's unheard of conUnique variables for replicasHow can I assign a different token environment variable to each replica? Or have the replicas chooseDelete Strapi build and .cache foldersHello, how can I get a list of files in my railway project? I tried the command `railway run ls` buUnable to add repository to service that I'm a collaborator onI'm a collaborator on a github repo, and I'm trying to deploy a service on railway using that repo. Deploy angular project on RailwayI have angular project which I can build and run on my local machine perfectly. here is the link of Issue when deploying Typebot templateLooks like something went wrong and the train derailed... Hello, I have tried deploying both TypeboBun + Next JS 14 + Dockerfile run build failed timed outHi! The run build crashes due to timeout, please look, what's wrong with this? Service ID 9783c8b7-cExtremely expensive by previous standardsI've been using Railway for more than a year and a half, and for the first time I've seen such nonseI am charged twice for the same BDI have double database since the migration, and I am being billed twice as much, I have several dataRailway projects suddenly failing with new "Cannot find type definition file for 'mime'" ErrorSeems that something changed in the Railway infra because even 'redeploying' previously working projWebdriver Exception:Process unexpectedly closed with status: 1I am using selenium 4.19.0, and Firefox as the webdriver with headless configuration. My code works I need help restoring the postgres dataI accidentally used prisma migrate and overwrote the data in my production database. Can someone f