Build failing
Hello
I am trying to deploy a MERN app but the build failed multiple times.
I am fairly new to Railway, however when I tested the platform a couple of months ago I was able to deploy another app, very similar in structure to this one (React, Node, Express and Mongo DB) without problems, while this time it is not even building.
Service id: ad4153e7-5a67-4029-8ceb-053a56176d47
Thank you in advance for your help
// from the build logs
ERROR: failed to solve: process "/bin/bash -ol pipefail -c yarn run build" did not complete successfully: exit code: 1
Error: Docker build failed
61 Replies
Project ID:
ad4153e7-5a67-4029-8ceb-053a56176d47
full build logs please https://bookmarklets.up.railway.app/log-downloader/
attached
what kind of app is this?
it is a simple app where you can create, edit, delete tasks that get saved in a Mongo database.
the code works perfectly on localhost.
I use yarn-run-all for the production environment to run the react build and the API
a simple REST API built in Express
I was looking for a higher level answer like "it's a react app"
either way, your dependencies are outdated, please update them
yes I mentioned above
(React, Node, Express and Mongo DB)
is that the reason ?
there's a very good chance, something is needing a deprecated openssl v1 hashing function, upgrading your dependencies will likely fix this problem
ok will try thanks
I upgraded a few but I think the issue was with the react-scripts package.
Now the app is deployed successfully, and I generated a domain, but I get a message "Application failed to respond" and the browser shows a 503 error.
do you have express serving your react app?
yes
can you show me that code?
for express?
yes, the express code that serves the react app
this is code I used on the previous app and worked
okay thats good enough
there is some cors code also, I configured the env variables but maybe that is causing issues
this page covers the problem, please read https://docs.railway.app/troubleshoot/fixing-common-errors
I added the 0.0.0.0 and my log file says Backend app listening on port 4000! as desired
still getting a 503 though
read the doc page i linked please
now listening on railway port ... I am seeing the API page/message though
send the railway domain please
cool, its working
yes but I am expecting the frontend/react served there
as I have this
you have a route that returns that text already registered on the root, remove it since it is taking priority
yes a / route
but the other one is a wildcard *
this is a config I had working on railway a couple of months ago
yep, an actual
/
route will take priority over a wildcard route
this is true for almost every router for nearly any languageok
the most ideal situation would be two railway services, one for the frontend and one for the backend
and in your repo you would separate each codebase into separate
/frontend
and /backend
folders
express isn't really meant to be serving a frontend site, it's not ideal how you are currently doing itin my repo, I have separate folders
and then they are connected
is this an NX or turbo repo?
but yes, this solution to serve the app with express is one that another dev showed me, but not something I have done, and maybe not the best solution...
it's definitely not the best, though it is still far better than using the development server built into react scripts to run the site, so I will give you that much lol
nx or turborepo, not sure, I have a standard repo on github
okay so just (no offense) an incorrectly structured repo
probably
would you be interested in walking through the proper setup? two railway services, structuring your repo correctly, etc. or do you just want what you have to work?
I would say as it is 2am where I am, I may try and remove the / route and see what happens.... then maybe when I have a bit more time, yes I would be interested in setting it up correctly
okay let me know how those route changes go
it is not working now
as I have set other env variables but probably not correctly
as my code needs
this would be a code issue, is there anything in the deployment logs?
I need a variable for the DB, and that one works
I need one for the API in production
and one for the frontend (to whitelist it)
okay go ahead and set that up https://docs.railway.app/develop/variables
I did but unsuccessfully
what do the deployment logs say
Error: Not allowed by CORS
like the whitelisting is not right
code issue, please go and read the docs for the cors middleware you are using
yes but how would I identify the frontend here ?
that's what you are going to read the docs for
https://expressjs.com/en/resources/middleware/cors.html
the thing is locally I have a UI_URL_WHITELIST="http://localhost:3000 ...
and that works fine
if I add the Railway URL though, it's blocked
I will restart tomorrow. thanks a lot
you can add more then one, please read the docs i linked
will do tomorrow, thank you
good morning, although I am still working on it (understanding more about available env variables etc.), I had success for the moment allowing the railway domain as origin.
I also had to do another adjustment, in another env variable.
Thank you very much for your support so far, and if you want to direct me to a better solution with the separate frontend and backend repos, I will be happy to read your suggestions.
just to clarify: is it correct that listening to "0.0.0.0" means "all IP addresses on the local machine" (ie the server could be accessed through more than one IP)?
it's more so you need to listen on that ip so that your app can be accessed outside of its container
im going to need more context
sorry the msg disapperared
you cant edit message with links
the bot doesnt like that
when reloading a route like items/id
browser not finding files that are referenced from react app index.html
the icon and a json
i think you should read the frameworks docs for help on this one
ok
these threads are for help with the platform, not so much coding help
understood