Installing dependencies for sub directories

My project have this structure
root/
├── client/ (React app)
| ├── .env
| ├── .package.json
| └── src/
├── server/ (Node server)
| ├── .env
| ├── .package.json
| └── src/
└── package.json
root/
├── client/ (React app)
| ├── .env
| ├── .package.json
| └── src/
├── server/ (Node server)
| ├── .env
| ├── .package.json
| └── src/
└── package.json
To run it successfully one have to: 1. install dependencies for both client and server. 2. build the client. 3. start the server In the root's package.json I have this script to install client and server dependencies:
"install": "npm install --prefix client & npm install --prefix server"
"install": "npm install --prefix client & npm install --prefix server"
In local development this works, dependencies both for client first and then server are installed, although the process doesn't exit on its own, I have to manually press Ctrl-C, but then all the next steps work just fine and I can run the application as expected. However when deploy it to railway although it installs the dependencies it fails at the next step (build) because it cannot find both react-script and rimraf, which are necessary to run the build script, which leds me to think that it is not installing the dependencies correctly how can I tell railway to install dependencies for client/ and server/?
31 Replies
Percy
Percy8mo ago
Project ID: 80b7a72a-2271-48a0-8bc9-a5758f24c847
Ghost Order
Ghost OrderOP8mo ago
80b7a72a-2271-48a0-8bc9-a5758f24c847
Brody
Brody8mo ago
are you able to share the repo?
Ghost Order
Ghost OrderOP8mo ago
GitHub
GitHub - GhostOrder28/inmobitas: New repo for my real estate manage...
New repo for my real estate manager project, it combines both client and server codebases to a more convenient deployment - GhostOrder28/inmobitas
Brody
Brody8mo ago
do the client and server import stuff from one another?
Ghost Order
Ghost OrderOP8mo ago
no imports, just the build script in the client's package.json removes and creates a directory in server
Brody
Brody8mo ago
so the server serves the client app?
Ghost Order
Ghost OrderOP8mo ago
yep, client basically just build the frontend files into a public/ dir that is located inside server/ and then the server can serve those static files
Brody
Brody8mo ago
interesting approach can you send me your latest build logs please - https://bookmarklets.up.railway.app/log-downloader/
Ghost Order
Ghost OrderOP8mo ago
well before I had both on separated repos, but then I always ended duplicating the commit messages for both, since every change in the client repo forces also an update in the server repo because it serves the static files generated by create-react-app in client xD sure let me check the link
Brody
Brody8mo ago
interesting in that the server is serving the client, not that you have both apps in one repo because that part is normal. in my experience its best to have the client (or frontend) serve itself and the backend serve itself (for lack of a better term)
Ghost Order
Ghost OrderOP8mo ago
oh mmm, yeah certainly that's another common approach
Brody
Brody8mo ago
try adding a nixpacks.toml to your project with this in it -
[phases.install]
cmds = ['npm run install']
[phases.install]
cmds = ['npm run install']
Ghost Order
Ghost OrderOP8mo ago
ok it failed again with the same error, rimraf and react-scripts not found
Brody
Brody8mo ago
new build logs please
Ghost Order
Ghost OrderOP8mo ago
oh right, sorry
Brody
Brody8mo ago
then i might recommend moving to npm workspaces, it would help here
Ghost Order
Ghost OrderOP8mo ago
I see, well thank you for your time brody, I will read more about that or maybe I just go with the more common approach you mentioned 😅
Brody
Brody8mo ago
haha that too
Ghost Order
Ghost OrderOP8mo ago
I don't know why but I just completely forgot that the client having its own little sever to serve just the build files is a thing xD
Brody
Brody8mo ago
and thats easily achievable with the nixpacks.toml and Caddyfile from this repo https://github.com/brody192/create-react-app-starter
Ghost Order
Ghost OrderOP8mo ago
oh, I was thinking in creating a barebones nodejs server inside the client and serve the build files through it
Brody
Brody8mo ago
thats also not ideal its best to use a web server as a web server, and node for node stuff
Ghost Order
Ghost OrderOP8mo ago
well that's right I will read more on nix and cady, thank you
Brody
Brody8mo ago
you would only need to read about it if you want to learn more, those two files are drag and drop
Ghost Order
Ghost OrderOP8mo ago
yep, I always try to know understand at least the basics of the technology I use in my apps so I can customize it when I needed or have some notion of where to look at but having an easy quick start helps
Brody
Brody8mo ago
love that attitude
Ghost Order
Ghost OrderOP8mo ago
hehe, I guess being self taught helped to build it
Brody
Brody8mo ago
for sure
Want results from more Discord servers?
Add your server