Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with deploying React based app on Railway

I was moving my fullstack app (React + Express) from Heroku. The problem was that React app has to be built for running (also has to install required dependencies), but on git we usually store only raw source code.

A common structure for fullstack projects:

enter image description here

Heroku has the option to run scripts after deployment with a special script in the package.json file:

"heroku-postbuild": "npm install --prefix client && npm run build --prefix client"

But I didn't find a similar ability on Railway.

So my solution is:

  1. Remove the build folder from the .gitignore file
  2. Build react app with npm run build
  3. Add all to git repository
  4. Deploy on Railway via Git Repo
  5. Do not forget to add environment variables
  6. Create domain name to have access via public internet
  7. Be happy!

I had some problems with this, so I am sharing the easiest solution for others.

like image 753
Zorro Avatar asked Sep 19 '25 13:09

Zorro


1 Answers

By selecting a project on Railway, and going to its settings, you would find a field named Build Command. There you can add your build commands. For example, in your specific case, this should work:

cd client && npm install && npm run build && cd .. && npm i

If it does not work, look at your project structure and adapt the command. Currently, the field is there:

enter image description here

like image 147
yousoumar Avatar answered Sep 22 '25 01:09

yousoumar