Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to load resources error 404 while deploying create-react-app

Any help would be GREATLY appreciated. Thank you!

I can run my website fine locally, but am having problems when deploying it in production. When I run npm run deploy, it should automatically build into production.

enter image description here

Here's part of my package.json for the deploy command:

{
    "name": "barrex",
    "version": "0.1.0",
    "homepage": "https://patrickhuang94.github.io/barrex",
    "devDependencies": {
        "gh-pages": "^0.12.0",
        "react-scripts": "0.9.5"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",    
        "deploy": "npm run build&&gh-pages -d build"
    }
}

Everything on my gh-pages is set up correctly. When I run the URL I specified in my 'homepage' field (Barrex), it's redirecting to my custom domain. But my custom domain can't find the .js files that was supposed to be created with npm run deploy. Can someone explain why it runs ok on local machine, but can't find resources in production?

like image 397
patrickhuang94 Avatar asked Mar 25 '17 00:03

patrickhuang94


1 Answers

As it says in the screenshot, the project was built assuming it would be hosted at /barrex/.
However you are serving it from the server root.

Change homepage in package.json to your custom domain (http://www.barrexus.com/). Next time you build, it will infer / as the path project is hosted on, and use that instead.

like image 166
Dan Abramov Avatar answered Sep 22 '22 12:09

Dan Abramov