Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The React App works during `npm start` but returns 404 after build

I'm developing a React App and everything works fine during npm start. After I do npm run build and run serve -s build under the build folder, the terminal told me it's serving but when I checked out http://localhost:5000/, it was

404 The requested path could not be found

Then I installed live-server and run live-server under the build folder, the App worked fine again. But I don't understand why serve -s build was not working properly.

Any ideas?

like image 322
randomcat Avatar asked Jan 29 '19 15:01

randomcat


Video Answer


1 Answers

This doesn't work because you're running the command from inside the build folder already.

If you run serve --help you can see the usage documentation for this command. The serve command accepts an input of folder_name for the files it should serve. If no folder is specified it will serve the folder that you are running the command in (which is why Gabriele's response above solved your problem). You could run the serve -s build command from the parent folder that contains the build folder and it would also work.

like image 125
Chris Avatar answered Oct 18 '22 22:10

Chris