(React with Vite) -> ReactRouter 404 Routing Error on Page reload

Hi everybody! I hosted a react app on this platform and I'm getting 404 errors on page reloads. Going through react-router docs, I discovered this -"If you're hosting your app on a static file server, you'll need to configure it to send all requests to your index.html to avoid getting 404s." Project ID 6246ef0f-5ee8-4207-94b6-f183d98e7c85
18 Replies
Percy
Percy14mo ago
Project ID: 6246ef0f-5ee8-4207-94b6-f183d98e7c85
Brody
Brody14mo ago
show me your package.json file please
danielthames
danielthames14mo ago
These are the script wath I've used this one works npx http-server ./dist for start and this one bellow caused an error "scripts": { "dev": "vite --port 3001", "build": "tsc && vite build", "preview": "vite preview", "start": "serve dist -s -n -L -p $PORT" }, sh: 1: serve: not found npm WARN config production Use --omit=dev instead.
frontend@0.0.0 start serve build -s -n -L -p $PORT
sh: 1: serve: not found npm WARN config production Use --omit=dev instead.
frontend@0.0.0 start serve build -s -n -L -p $PORT
sh: 1: serve: not found
Brody
Brody14mo ago
do you have any build or start commands defined in your railway service settings?
danielthames
danielthames14mo ago
noup
danielthames
danielthames14mo ago
please let me know if you want to access to my github repo
Brody
Brody14mo ago
just run npm i serve in your local project and then push the changes also why run tsc before vite build? vite should handle ts building and bundling itself right?
danielthames
danielthames14mo ago
I should keep this command after that, right? "start": "serve dist -s -n -L -p $PORT" ok, only vite build then All right! pushin it now "scripts": { "dev": "vite --port 3001", "build": "vite build", "preview": "vite preview", "start": "serve dist -s -n -L -p $PORT" },
Brody
Brody14mo ago
lmao
danielthames
danielthames14mo ago
OMG
Brody
Brody14mo ago
one command is all it took
danielthames
danielthames14mo ago
It's working now! steps for the next person who has this issue 1.- run -> npm i serve 2.- make sure to have the scripts simillar like this "scripts": { "dev": "vite --port 3001", "build": "vite build", "preview": "vite preview", "start": "serve dist -s -n -L -p $PORT" }, the start command it's mandatory for a better deployment
Brody
Brody14mo ago
i mean i also have this guide
danielthames
danielthames14mo ago
thank you very much Brody!
Brody
Brody14mo ago
no problem 🙂
Want results from more Discord servers?
Add your server
More Posts