Build seems to use wrong environment

scookdev
PRO

2 years ago

I'm trying to deploy the client-side of my app which is a React site. I've installed the `serveupdated my scripts in package.json:

Solved

16 Replies

scookdev
PRO

2 years ago

Sorry, I didn't mean to submit that (and can't edit it). Here it is again.

I'm trying to deploy the client-side of my app which was built with create-react-app. Per instructions here - https://help.railway.app/project-help/f9v3gkPQRy4UShk5SnoPDH/getting-your-create-react-app-running-on-railway/qHRsgxa5n57xLp1yVgk9fP - I've installed the serve Node package and updated my package.json -

  "scripts": {
    "start": "serve build -s -n -L -p $PORT",
    "dev": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

I also added a variable in the client process NODE_ENV=production because no matter what, it seems to think the env is development. This is from the logs:

yarn run v1.22.19
$ react-scripts start
/bin/sh: 1: react-scripts: not found
error Command failed with exit code 127.

I'm not sure why it's running that - it should be running yarn run start which will run serve. Any suggestions on how to get it to run serve?


2 years ago

could be that the start command is being overwritten somewhere, check the start command in the service settings.


scookdev
PRO

2 years ago

Thank you Brody - I don't have a Custom Build Command set.


2 years ago

right but check for a custom start command.


scookdev
PRO

2 years ago

Sorry - no I didn't have any custom commands. But I just added a custom start command - yarn run start- now I'm getting the error

yarn run v1.22.19
$ serve build -s -n -L -p $PORT
/bin/sh: 1: serve: not found
error Command failed with exit code 127.

but serve is definitely a dependency: "serve": "^14.2.1",

I didn't see anything in the documentation, but build is still

 "build": "react-scripts build",

so that might be the issue. I guess I can change that to use serve as well


2 years ago

serve is an npm package, it would need to be part of your dependencies.

edit, could you share your repo?


scookdev
PRO

2 years ago

Yes, it is a dependency. The snipped was from my package.json. The repo's private, but I can add you as a collaborator if you like.


2 years ago

yes please, my username is brody192


scookdev
PRO

2 years ago

Well, it's making me add a seat since it's an enterprise account. I created a gist with the package.json of the client app -> https://gist.github.com/scookdev/48bdfb505036affdc3a023b5a9f9e880


2 years ago

i thought you where going to add me to your github repo


scookdev
PRO

2 years ago

I tried but with an enterprise account you have to add a seat to add a collaborator, which I don't want to do. I'm going to see if I can take the repo out of the account, that way I can add you.


scookdev
PRO

2 years ago

OK, done - sent you an invite


2 years ago

looking now


2 years ago

you have a Dockerfile Railway will always use one if present, It runs yarn dev.
renamed the Dockerfle to [Dockerfile.dev](Dockerfile.dev) or similar.

also, you may be interested in a better / more efficient method of serving your frontend app.

https://github.com/brody192/create-react-app-starter

This example repo uses caddy to serve the client site, its far less resource intensive compared to serve

all you should need to do is copy the nixpacks.toml and Caddyfile from that repo into your client folder, and remove the custom start command from your service settings


Status changed to Solved Railway over 1 year ago


scookdev
PRO

2 years ago

That's great - thanks so much, Brody.


2 years ago

happy to help, let me know if the caddy solution works for you


Build seems to use wrong environment - Railway Help Station