4
votes

create-react-app build is not working in subdirectory on web server. I’ve used express node web server. ‘create-react-app build’ is working on root directory.But, It doesn’t work on subdirectory.

For example,

localhost/ - It works. localhost/react-app/ - It doesn’t work.

load related files normally. There are no errors and warnings. It's look like blank page. Surely I configured ‘homepage field’ in package.json. I don’t know why this situation occur. The followings are my configuration.

  1. set express for react



    app.get('/*',function(req,res){ res.sendFile(path.resolve(config.static_root+'/react-app', 'index.html')); });

  2. add homepage field to package.json


    "homepage": "localhost/react-app"


  3. npm run build

  4. copy files form build folder and move to /react-app folder.

1
Did you type http://localhost/react-app into the homepage field? I'm not sure it would get parsed correctly without the protocol. - Dan Abramov
con you post your entire package.json? - Cleanshooter
I had a similar issue... I used npm init in my main project and ejected my react app into my main project. You may have a second "homepage" in your package.json overwriting the one think is getting used. - Cleanshooter

1 Answers

3
votes

Try adding the directory name, or ./ to package.json, like so:

"homepage": "./"