R
Railway14mo ago
Nico

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
Percy
Percy14mo ago
Project ID: ad4153e7-5a67-4029-8ceb-053a56176d47
Nico
NicoOP14mo ago
Brody
Brody14mo ago
what kind of app is this?
Nico
NicoOP14mo ago
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
Brody
Brody14mo ago
I was looking for a higher level answer like "it's a react app" either way, your dependencies are outdated, please update them
Nico
NicoOP14mo ago
yes I mentioned above (React, Node, Express and Mongo DB) is that the reason ?
Brody
Brody14mo ago
there's a very good chance, something is needing a deprecated openssl v1 hashing function, upgrading your dependencies will likely fix this problem
Nico
NicoOP14mo ago
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.
Brody
Brody14mo ago
do you have express serving your react app?
Nico
NicoOP14mo ago
yes
Brody
Brody14mo ago
can you show me that code?
Nico
NicoOP14mo ago
for express?
Brody
Brody14mo ago
yes, the express code that serves the react app
Nico
NicoOP14mo ago
this is code I used on the previous app and worked
// serve static files
app.use(express.static(path.join(__dirname, "../../build")));

// serve index.html on all routes - strategy to make reloads work on all (not "/") routes with react 'BrowserRouter'
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "../../public", "index.html"));
});
// serve static files
app.use(express.static(path.join(__dirname, "../../build")));

// serve index.html on all routes - strategy to make reloads work on all (not "/") routes with react 'BrowserRouter'
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "../../public", "index.html"));
});
Brody
Brody14mo ago
okay thats good enough
Nico
NicoOP14mo ago
there is some cors code also, I configured the env variables but maybe that is causing issues
Brody
Brody14mo ago
this page covers the problem, please read https://docs.railway.app/troubleshoot/fixing-common-errors
Nico
NicoOP14mo ago
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
Brody
Brody14mo ago
read the doc page i linked please
Nico
NicoOP14mo ago
now listening on railway port ... I am seeing the API page/message though
Brody
Brody14mo ago
send the railway domain please
Brody
Brody14mo ago
cool, its working
{"message":"Node | Express"}
{"message":"Node | Express"}
Nico
NicoOP14mo ago
yes but I am expecting the frontend/react served there as I have this
Brody
Brody14mo ago
you have a route that returns that text already registered on the root, remove it since it is taking priority
Nico
NicoOP14mo ago
yes a / route but the other one is a wildcard * this is a config I had working on railway a couple of months ago
Brody
Brody14mo ago
yep, an actual / route will take priority over a wildcard route this is true for almost every router for nearly any language
Nico
NicoOP14mo ago
ok
Brody
Brody14mo ago
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 it
Nico
NicoOP14mo ago
in my repo, I have separate folders
src/api
src/frontend
src/api
src/frontend
and then they are connected
Brody
Brody14mo ago
is this an NX or turbo repo?
Nico
NicoOP14mo ago
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...
Brody
Brody14mo ago
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
Nico
NicoOP14mo ago
nx or turborepo, not sure, I have a standard repo on github
Brody
Brody14mo ago
okay so just (no offense) an incorrectly structured repo
Nico
NicoOP14mo ago
probably
Brody
Brody14mo ago
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?
Nico
NicoOP14mo ago
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
Brody
Brody14mo ago
okay let me know how those route changes go
Nico
NicoOP14mo ago
it is not working now as I have set other env variables but probably not correctly as my code needs
Brody
Brody14mo ago
this would be a code issue, is there anything in the deployment logs?
Nico
NicoOP14mo ago
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)
Brody
Brody14mo ago
okay go ahead and set that up https://docs.railway.app/develop/variables
Nico
NicoOP14mo ago
I did but unsuccessfully
Brody
Brody14mo ago
what do the deployment logs say
Nico
NicoOP14mo ago
Error: Not allowed by CORS like the whitelisting is not right
Brody
Brody14mo ago
code issue, please go and read the docs for the cors middleware you are using
Nico
NicoOP14mo ago
yes but how would I identify the frontend here ?
Brody
Brody14mo ago
that's what you are going to read the docs for https://expressjs.com/en/resources/middleware/cors.html
Nico
NicoOP14mo ago
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
Brody
Brody14mo ago
you can add more then one, please read the docs i linked
Nico
NicoOP14mo ago
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)?
Brody
Brody14mo ago
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
Nico
NicoOP14mo ago
sorry the msg disapperared
Brody
Brody14mo ago
you cant edit message with links the bot doesnt like that
Nico
NicoOP14mo ago
when reloading a route like items/id browser not finding files that are referenced from react app index.html the icon and a json
Brody
Brody14mo ago
i think you should read the frameworks docs for help on this one
Nico
NicoOP14mo ago
ok
Brody
Brody14mo ago
these threads are for help with the platform, not so much coding help
Nico
NicoOP14mo ago
understood
Want results from more Discord servers?
Add your server