Cannot find package even installed

I'm deploying a Discord bot but I'm getting this returned error, the package is installed and working fine on local
No description
Solution:
in your dockerfile, run a prune and then copy the node_modules folder into the final layer
Jump to solution
43 Replies
Percy
Percy7mo ago
Project ID: N/A
Brody
Brody7mo ago
is it installed in the dependencies or the dev dependencies
Vitagliano
VitaglianoOP7mo ago
Dependencies
Brody
Brody7mo ago
is your lock file in sync
Vitagliano
VitaglianoOP7mo ago
Should be
## build runner
FROM node:lts-alpine as build-runner

# Set temp directory
WORKDIR /tmp/app

# Move package.json
COPY package.json .

# Install dependencies
RUN yarn install

# Move source files
COPY src ./src
COPY tsconfig.json .
COPY prisma ./prisma

# Generate Prisma Client
RUN npx prisma generate

# Build project
RUN yarn run build

## production runner
FROM node:lts-alpine as prod-runner

# Set work directory
WORKDIR /app

# Copy package.json from build-runner
COPY --from=build-runner /tmp/app/package.json /app/package.json

# Move build files
COPY --from=build-runner /tmp/app/build /app/build

# Start bot
CMD [ "yarn", "run", "start" ]
## build runner
FROM node:lts-alpine as build-runner

# Set temp directory
WORKDIR /tmp/app

# Move package.json
COPY package.json .

# Install dependencies
RUN yarn install

# Move source files
COPY src ./src
COPY tsconfig.json .
COPY prisma ./prisma

# Generate Prisma Client
RUN npx prisma generate

# Build project
RUN yarn run build

## production runner
FROM node:lts-alpine as prod-runner

# Set work directory
WORKDIR /app

# Copy package.json from build-runner
COPY --from=build-runner /tmp/app/package.json /app/package.json

# Move build files
COPY --from=build-runner /tmp/app/build /app/build

# Start bot
CMD [ "yarn", "run", "start" ]
My Dockerfile
Brody
Brody7mo ago
try utilizing a lock file and install from the lock file
Vitagliano
VitaglianoOP7mo ago
So I should try sending my yarn.lock together?
Brody
Brody7mo ago
not sure what you mean by sending
Vitagliano
VitaglianoOP7mo ago
Commiting together
Brody
Brody7mo ago
your lock file should definitely be in your repo, and used to install the dependencies from
Vitagliano
VitaglianoOP7mo ago
Let me try
Brody
Brody7mo ago
are you sure railway is using your Dockerfile?
Vitagliano
VitaglianoOP7mo ago
Yes
No description
Vitagliano
VitaglianoOP7mo ago
Not sure if it's using right
Brody
Brody7mo ago
there's just some simple config issue somewhere with your project
Vitagliano
VitaglianoOP7mo ago
Even with the yarn.lock file still the same error
Brody
Brody7mo ago
please show me the updated dockerfile
Vitagliano
VitaglianoOP7mo ago
Still the same
Vitagliano
VitaglianoOP7mo ago
No description
Brody
Brody7mo ago
please see my message, this requires you to change the dockerfile a little bit
Vitagliano
VitaglianoOP7mo ago
## build runner
FROM node:lts-alpine as build-runner

# Set temp directory
WORKDIR /tmp/app

# Move package.json and yarn.lock
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install

# Move source files
COPY src ./src
COPY tsconfig.json .
COPY prisma ./prisma

# Generate Prisma Client
RUN npx prisma generate

# Build project
RUN yarn run build

## production runner
FROM node:lts-alpine as prod-runner

# Set work directory
WORKDIR /app

# Copy package.json from build-runner
COPY --from=build-runner /tmp/app/package.json /app/package.json
COPY --from=build-runner /tmp/app/yarn.lock /app/yarn.lock

# Move build files
COPY --from=build-runner /tmp/app/build /app/build

# Start bot
CMD [ "yarn", "run", "start" ]
## build runner
FROM node:lts-alpine as build-runner

# Set temp directory
WORKDIR /tmp/app

# Move package.json and yarn.lock
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install

# Move source files
COPY src ./src
COPY tsconfig.json .
COPY prisma ./prisma

# Generate Prisma Client
RUN npx prisma generate

# Build project
RUN yarn run build

## production runner
FROM node:lts-alpine as prod-runner

# Set work directory
WORKDIR /app

# Copy package.json from build-runner
COPY --from=build-runner /tmp/app/package.json /app/package.json
COPY --from=build-runner /tmp/app/yarn.lock /app/yarn.lock

# Move build files
COPY --from=build-runner /tmp/app/build /app/build

# Start bot
CMD [ "yarn", "run", "start" ]
What else should I change?
Brody
Brody7mo ago
install from the lock file
Vitagliano
VitaglianoOP7mo ago
I don't know how to do that to be honest Tried RUN yarn install --frozen-lockfile
Brody
Brody7mo ago
that is what you would want to be using in a production environment
Vitagliano
VitaglianoOP7mo ago
And what should I use now?
Brody
Brody7mo ago
exactly what you just sent
Vitagliano
VitaglianoOP7mo ago
## build runner
FROM node:lts-alpine as build-runner

# Set temp directory
WORKDIR /tmp/app

# Move package.json and yarn.lock
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install --frozen-lockfile

# Move source files
COPY src ./src
COPY tsconfig.json .
COPY prisma ./prisma

# Generate Prisma Client
RUN npx prisma generate

# Build project
RUN yarn run build

## production runner
FROM node:lts-alpine as prod-runner

# Set work directory
WORKDIR /app

# Copy package.json from build-runner
COPY --from=build-runner /tmp/app/package.json /app/package.json
COPY --from=build-runner /tmp/app/yarn.lock /app/yarn.lock

# Move build files
COPY --from=build-runner /tmp/app/build /app/build

# Start bot
CMD [ "yarn", "run", "start" ]
## build runner
FROM node:lts-alpine as build-runner

# Set temp directory
WORKDIR /tmp/app

# Move package.json and yarn.lock
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install --frozen-lockfile

# Move source files
COPY src ./src
COPY tsconfig.json .
COPY prisma ./prisma

# Generate Prisma Client
RUN npx prisma generate

# Build project
RUN yarn run build

## production runner
FROM node:lts-alpine as prod-runner

# Set work directory
WORKDIR /app

# Copy package.json from build-runner
COPY --from=build-runner /tmp/app/package.json /app/package.json
COPY --from=build-runner /tmp/app/yarn.lock /app/yarn.lock

# Move build files
COPY --from=build-runner /tmp/app/build /app/build

# Start bot
CMD [ "yarn", "run", "start" ]
Brody
Brody7mo ago
please update your dockerfile with this
Vitagliano
VitaglianoOP7mo ago
Still giving the same error
Brody
Brody7mo ago
locally, delete your node_modules and then run yarn install --frozen-lockfile and start your project
Vitagliano
VitaglianoOP7mo ago
Now what? No errors
Brody
Brody7mo ago
what node version are you using locally
Vitagliano
VitaglianoOP7mo ago
20.11.0
Brody
Brody7mo ago
what version of node is node:lts-alpine
Vitagliano
VitaglianoOP7mo ago
I'm not sure, I think it's the last one available
Brody
Brody7mo ago
its 20.13.1
Vitagliano
VitaglianoOP7mo ago
So I might need to define the node version?
Brody
Brody7mo ago
try using node:20.11.0-alpine
Solution
Brody
Brody7mo ago
in your dockerfile, run a prune and then copy the node_modules folder into the final layer
Vitagliano
VitaglianoOP7mo ago
You mean
COPY --from=build-runner /tmp/app/node_modules /app/node_modules
COPY --from=build-runner /tmp/app/node_modules /app/node_modules
?
Brody
Brody7mo ago
please take everything i said in this message into account
Vitagliano
VitaglianoOP7mo ago
Working fine now @Brody Thank you so much
Brody
Brody7mo ago
no problem
Want results from more Discord servers?
Add your server