R
Railway15mo ago
luci1

node_modules

I'm trying to deploy using my build script. The build script consist in install normally the packages (including the development packages), but after, I need to remove the node_modules file to install only the production package's, but I got the error about .cache folder #12 1.527 rm: cannot remove 'node_modules/.cache': Device or resource busy Someone knows a way to reinstall the node_modules only for production? The current build command:
tsup ./src && rm -rf node_modules src && yarn install --prod
tsup ./src && rm -rf node_modules src && yarn install --prod
The "tsup" will convert my TypeScript project to JavaScript project at dist folder, so I don't need the src folder anymore.
Solution:
its works with some changes ```docker FROM node:18.17.1-alpine3.18 AS base FROM base AS build...
Jump to solution
45 Replies
Percy
Percy15mo ago
Project ID: N/A
Brody
Brody15mo ago
you should not be installing the node modules in the build command but first, is node_modules in your .gitignore?
luci1
luci115mo ago
of course i'm trying to reinstall the node_modules to reduce the project size
Brody
Brody15mo ago
does the initial build with tsup need dev dependencies?
luci1
luci115mo ago
the tsup is a dev dependencie, I don't need tsup to run the project, just for convert typescript to javascript during the build command
Brody
Brody15mo ago
isnt there a trim command that will remove dev deps? tsup ./src && yarn trim --dev
luci1
luci115mo ago
i'll try, one moment
Brody
Brody15mo ago
dont know if thats a thing, but you get the idea no no, i just made that up you need to check for the actual flag and syntax
luci1
luci115mo ago
does command works for yarn v1 (classic)?
Brody
Brody15mo ago
again, i dont know it was a pseudo command
luci1
luci115mo ago
did not work Yasuo
Brody
Brody15mo ago
bruh ^
luci1
luci115mo ago
i tryed to run tsup ./src && rm -rf src && yarn install --prod but my build time got a lot more seconds
Brody
Brody15mo ago
^
luci1
luci115mo ago
sure do you know if pnpm can do it?
Brody
Brody15mo ago
npm can
luci1
luci115mo ago
with prune?
Brody
Brody15mo ago
npm prune --production
luci1
luci115mo ago
pnpm too
Brody
Brody15mo ago
honestly just use npm, ive never seen much of a benefit with yarn or pnpm
luci1
luci115mo ago
nothing new, #12 2.315 up to date, audited 349 packages in 962ms, the correct is under of 300 packages running the following script:
tsup ./src && rm -rf src && npm prune --omit=dev
tsup ./src && rm -rf src && npm prune --omit=dev
but keeps uploading 235.4MB project_id: 56101361-0f25-4fa0-acf1-9524a7ab9a3d
Brody
Brody15mo ago
I mean, is 235 such a big deal? but for real, what you're trying to do would best be achieved in a multistage dockerfile
luci1
luci115mo ago
yes, i'm think this too
luci1
luci115mo ago
always was 200+ MB
luci1
luci115mo ago
i'll read the docs for the moment to implements dockerfile
Brody
Brody15mo ago
just have a Dockerfile in your project and railway will build with a dockerfile, but railway doesn't have any docs on how to write a dockerfile, since there are already so many great resources on that
luci1
luci115mo ago
do you know a documentation to create a Dockerfile? i just know how to use docker compose i have never used dockerfile before
Brody
Brody15mo ago
not off the top of my head, I'm sure you can find plenty of resources on Google though
luci1
luci115mo ago
ok, i'll search Ziggs is a good size? or i can reduce more? my project is very small
luci1
luci115mo ago
only theses javascript files (and the prisma orm), and probably is not more than 100mb
luci1
luci115mo ago
or... maybe the prisma is the large size?
Brody
Brody15mo ago
what node image are you using?
luci1
luci115mo ago
alpine
Brody
Brody15mo ago
let's see the dockerfile
luci1
luci115mo ago
hmm... i'm working around the dockerfile, because it's not copying my dist (generated by yarn build) folder probably because its in .gitignore file
Brody
Brody15mo ago
send the file anyway also, have you said what kind of app this is yet? apologies if you have
luci1
luci115mo ago
a common fastify/express backend app
luci1
luci115mo ago
Brody
Brody15mo ago
uh yeah that's not gonna work I'd rewrite that for you, but unfortunately I'm not at my computer right now
luci1
luci115mo ago
no problems bro Yasuo i'm close too
Brody
Brody15mo ago
lol not really tbh you are using CMD instead of RUN hey @luci give this a shot, but without seeing your code, i cant promise it will work
FROM node:18.17.1-alpine3.18 AS base

FROM base AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER false
ENV NPM_CONFIG_FUND false

WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn install

RUN yarn build

RUN npm prune --production

FROM base AS run

WORKDIR /app

COPY --from=build /app/node_modules/ ./
COPY --from=build /app/dist/ ./
COPY --from=build /app/package.json ./

CMD yarn start
FROM node:18.17.1-alpine3.18 AS base

FROM base AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER false
ENV NPM_CONFIG_FUND false

WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn install

RUN yarn build

RUN npm prune --production

FROM base AS run

WORKDIR /app

COPY --from=build /app/node_modules/ ./
COPY --from=build /app/dist/ ./
COPY --from=build /app/package.json ./

CMD yarn start
Solution
luci1
luci115mo ago
its works with some changes
FROM node:18.17.1-alpine3.18 AS base

FROM base AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER false
ENV NPM_CONFIG_FUND false

WORKDIR /app

COPY package.json yarn.lock ./
COPY prisma ./prisma/

RUN yarn install

COPY src ./src

RUN yarn build

RUN npm prune --omit=dev

FROM base AS run

WORKDIR /app

COPY --from=build /app/node_modules/ ./node_modules
COPY --from=build /app/dist/ ./dist
COPY --from=build /app/package.json ./

CMD yarn start
FROM node:18.17.1-alpine3.18 AS base

FROM base AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER false
ENV NPM_CONFIG_FUND false

WORKDIR /app

COPY package.json yarn.lock ./
COPY prisma ./prisma/

RUN yarn install

COPY src ./src

RUN yarn build

RUN npm prune --omit=dev

FROM base AS run

WORKDIR /app

COPY --from=build /app/node_modules/ ./node_modules
COPY --from=build /app/dist/ ./dist
COPY --from=build /app/package.json ./

CMD yarn start
With a total size of 157.3MB
Brody
Brody15mo ago
awesome, glad I could help
luci1
luci115mo ago
thanks bro Fizz
Brody
Brody15mo ago
no problem!
Want results from more Discord servers?
Add your server