R
Railway

✋|help

node_modules

Llucioroadtoglory8/20/2023
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


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
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
Jump to solution
Bbrody1928/20/2023
you should not be installing the node modules in the build command
but first, is node_modules in your .gitignore?
Llucioroadtoglory8/20/2023
of course
i'm trying to reinstall the node_modules to reduce the project size
Bbrody1928/20/2023
does the initial build with tsup need dev dependencies?
Llucioroadtoglory8/20/2023
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
Bbrody1928/20/2023
isnt there a trim command that will remove dev deps?
tsup ./src && yarn trim --dev
Llucioroadtoglory8/20/2023
i'll try, one moment
Bbrody1928/20/2023
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
Llucioroadtoglory8/20/2023
does command works for yarn v1 (classic)?
Bbrody1928/20/2023
again, i dont know it was a pseudo command
Llucioroadtoglory8/20/2023
did not work :Yasuo:
Bbrody1928/20/2023
bruh
^
Llucioroadtoglory8/20/2023
i tryed to run
tsup ./src && rm -rf src && yarn install --prod
but my build time got a lot more seconds
Bbrody1928/20/2023
^
Llucioroadtoglory8/20/2023
sure
do you know if pnpm can do it?
Bbrody1928/20/2023
npm can
Llucioroadtoglory8/20/2023
with prune?
Bbrody1928/20/2023
npm prune --production
Llucioroadtoglory8/20/2023
pnpm too
Bbrody1928/20/2023
honestly just use npm, ive never seen much of a benefit with yarn or pnpm
Llucioroadtoglory8/20/2023
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

but keeps uploading 235.4MB
project_id: 56101361-0f25-4fa0-acf1-9524a7ab9a3d
Bbrody1928/20/2023
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
Llucioroadtoglory8/20/2023
yes, i'm think this too
Llucioroadtoglory8/20/2023
always was 200+ MB
Llucioroadtoglory8/20/2023
i'll read the docs for the moment to implements dockerfile
Bbrody1928/20/2023
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
Llucioroadtoglory8/20/2023
do you know a documentation to create a Dockerfile? i just know how to use docker compose
i have never used dockerfile before
Bbrody1928/20/2023
not off the top of my head, I'm sure you can find plenty of resources on Google though
Llucioroadtoglory8/20/2023
ok, i'll search :Ziggs:
189.4MB is a good size? or i can reduce more?
my project is very small
Llucioroadtoglory8/20/2023
only theses javascript files (and the prisma orm), and probably is not more than 100mb
Llucioroadtoglory8/20/2023
or... maybe the prisma is the large size?
Bbrody1928/20/2023
what node image are you using?
Llucioroadtoglory8/20/2023
alpine
Bbrody1928/20/2023
let's see the dockerfile
Llucioroadtoglory8/20/2023
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
Bbrody1928/20/2023
send the file anyway
also, have you said what kind of app this is yet?
apologies if you have
Llucioroadtoglory8/20/2023
a common fastify/express backend app
Llucioroadtoglory8/20/2023
Bbrody1928/20/2023
uh yeah that's not gonna work
I'd rewrite that for you, but unfortunately I'm not at my computer right now
Llucioroadtoglory8/20/2023
no problems bro :Yasuo: i'm close too
Bbrody1928/21/2023
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
Solution
Llucioroadtoglory8/21/2023
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

With a total size of 157.3MB
Bbrody1928/21/2023
awesome, glad I could help
Llucioroadtoglory8/21/2023
thanks bro :Fizz:
Bbrody1928/21/2023
no problem!

Looking for more? Join the community!

Recommended Posts
Default Express template fails to deployHi, I've tried to deploy the ExpressJS template with no modifications, but am getting errors. Thx foQuestions about pricing for my customersHi, I'm planning to open a web agency and use Railway to deploy our customers' websites. Each customRailway IPv4Guys, does Railway "exports" IPv4 to another service allow its usage permission? I'm using a Redis s[PHP] Route all requests to index.phphttps://twitter.com/Shpigford/status/1693092242943025554I can't buy the planWhen I try to subscribe to the $5 plan, it gives me an error message saying "Your card does not suppI have a problem with my express applicationin the application status it says success but it is not displayed on the websitewhat is the reason for this error?npm WARN config production Use `--omit=dev` instead.Subscription already existsI can't enable the developer plan, the system returns the message: "Subscription already exists"FLASK APP failed to deployI used the refernce flask project idk why maybe the build/run command i put in was incorrect?503 error after binding to ipv6I get a 503 error after binding to ipv6 for internal communication between 2 services. attached my How do I link my services internally?Hello, I tried to figure it out on my own, but I have just ended up losing sleep haha. I'm having anBuild fails when pushing a project with docker-compose file.I am trying to link a project from cli and trying to push it to railway. i am using a docker composeQuestionsI have deployed my project. How can I put this project as asleep?my api wont start on railwayi tried remvoing nodemon from my start script and I also tried in my start script using "node index.cant see my domains in settingsI added domains last day and now i cant see and cant see even my generated free domain project id :laravel volume for the image storageHi! I have a Laravel application deployed via Github to a Railway service. The app is using a Localhello, I try to dump my database with MYSQLDUMP but always get an empty document and the following :stderr: /bin/sh: 1: mysqldump: not found @project: 61093780-ada7-48c8-baad-204a654316a2 @environmentuseSWR different behavior on railway?Hi I'm using useSWR hook on my react app frontend and instead of sending back the data the same way Railway fails to find correct version of pypi package discord-py-interactionsError log: ``` [stage-0 6/8] RUN --mount=type=cache,id=s/160fe6d3-84bb-4b29-a3bb-61b5f308406f-/root/typebot builder problemHello, i'm trying to login in the builder of typebot for the first time and when i put the mail to l