最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

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

{
    "name": "barrex",
    "version": "0.1.0",
    "homepage": "",
    "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?

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.

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?

Share Improve this question edited Aug 14, 2019 at 12:55 Edgar 6,85611 gold badges37 silver badges74 bronze badges asked Mar 25, 2017 at 0:07 patrickhuang94patrickhuang94 2,1156 gold badges36 silver badges63 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 21

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.

发布评论

评论列表(0)

  1. 暂无评论