【问题标题】:Deployed React app to github pages is blank将 React 应用程序部署到 github 页面是空白的
【发布时间】:2021-12-22 16:12:06
【问题描述】:

我正在按照https://github.com/gitname/react-gh-pages 的说明将我的 React 应用部署到 github 页面。

在链接中,我得到一个空白页和一个 404 错误: Failed to load resource: the server responded with a status of 404 ()

我的应用在本地主机上运行

我四处搜索,可能我的主页链接有误?

链接到我的仓库:https://github.com/PatgioK/pathfindingvisualizer

应用链接:https://patgiok.github.io/pathfindingvisualizer/

这是我的 package.json:

{
  "name": "pathfindingvisualizer",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://patgiok.github.io/pathfindingvisualizer/",
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "gh-pages": "^3.2.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "save-dev": "0.0.1-security",
    "web-vitals": "^1.1.2"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

【问题讨论】:

    标签: javascript reactjs github


    【解决方案1】:

    尝试通过在您的 packages.json 中添加 -b SomeBranchName 来指定部署脚本中的分支。

    所以:

    "scripts": {
        ...,
        "deploy": "gh-pages -d build -b SomeBranchName",
        ...
    

    【讨论】:

    • 你指的是什么部署脚本? npm run deploy 创建的分支是 gh-pages,在 package.json 中,我检查了它在我的 github 存储库设置中的 gh-pages 分支上
    • 我已经在我的回答中为你澄清了。
    • 你知道它为什么需要这个吗?我在网上找到的其他教程也没有提到这一点。
    • 我希望能告诉你,但我不知道。这只是我最近读到的关于使用 Gatsby 部署我的投资组合网站的内容,但不记得在哪里。
    【解决方案2】:

    您的仓库中的static 文件夹在哪里?这就是您的 404 页面所抱怨的。我检查了你的 GitHub 存储库,我也没有看到。

    【讨论】:

    • 我不知道?如果我做一个新的 create-react-app 也没有静态文件夹......
    猜你喜欢
    • 2021-10-13
    • 2017-11-03
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 2021-01-12
    • 2020-01-09
    相关资源
    最近更新 更多