【问题标题】:React app not deploying correctly in Github pagesReact 应用程序未在 Github 页面中正确部署
【发布时间】:2020-02-03 22:09:29
【问题描述】:

我按照教程将 React 应用程序部署到 github 页面。部署时,我没有收到任何错误消息,但是当我检查 URL 时,我只看到一个空白页面(请参阅https://bd21.github.io/tallyup-frontend-demo/)。

它使用“npm start”在本地运行良好。每当我部署时,我只运行“npm run deploy”。

我的仓库在这里:https://github.com/bd21/tallyup-frontend-demo

这是我的 package.json:

{
  "name": "tallyup-frontend-demo",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.22",
    "@fortawesome/free-solid-svg-icons": "^5.10.2",
    "@fortawesome/react-fontawesome": "^0.1.4",
    "@types/jest": "24.0.18",
    "@types/lodash": "^4.14.138",
    "@types/node": "12.7.4",
    "@types/react": "16.9.2",
    "@types/react-dom": "16.9.0",
    "@types/react-router-dom": "^4.3.5",
    "bootstrap": "^4.3.1",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "node-fetch": "^2.6.0",
    "react": "^16.9.0",
    "react-bootstrap": "^1.0.0-beta.12",
    "react-dom": "^16.9.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.1.1",
    "typescript": "3.6.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "homepage": "http://bd21.github.io/tallyup-frontend-demo",
  "devDependencies": {
    "gh-pages": "^2.1.1"
  }
}

当我在 Chrome 检查器中查看网络调用时,我没有看到任何 4xx 或 5xx 调用。你可以在这里验证。

https://bd21.github.io/tallyup-frontend-demo/

为什么我的应用无法正确部署/显示?

【问题讨论】:

    标签: reactjs github-pages


    【解决方案1】:

    您的网站在 Github 页面中正常运行,

    也许问题在于您的反应路由器代码,因为它正在路由某些东西

    【讨论】:

      【解决方案2】:

      当您使用“npm run deploy”时,您没有收到任何错误吗? 因为如果它运行没有任何错误,创建了«build»目录和«gh-pages»分支,那么您可以在«gh-pages»分支上轻松更改存储库的分支(用于设置中的github页面),几分钟后,您可以看到您自己的 github 页面。

      如果您完成了以上所有操作,请检查 «build» 目录中的 index.html。 它应该正确显示你的 React 项目的 html。

      我遇到的另一件事是,您应该为您的存储库添加 origin 远程(不是其他名称,只是 origin): Git远程添加源

      希望能帮到你。

      【讨论】:

        猜你喜欢
        • 2017-11-03
        • 1970-01-01
        • 1970-01-01
        • 2021-10-13
        • 1970-01-01
        • 2021-12-25
        • 2018-06-02
        • 2021-12-22
        • 1970-01-01
        相关资源
        最近更新 更多