【问题标题】:My react app appears blank after successfully deploying to github-pages成功部署到 github-pages 后,我的反应应用程序显示为空白
【发布时间】:2021-09-27 05:02:30
【问题描述】:

我正在尝试部署一个没有任何路由功能的反应应用。只需一个页面应用程序 到 github 页面,一切正常。部署时我没有收到任何错误,但部署后,应用程序是空白的,当我检查控制台时,我看到以下错误

    GET https://vicktor61.github.io/VickTor61/indecision-sniffle.git/static/css/main.aea680b0.chunk.css net::ERR_ABORTED 404
vicktor61.github.io/:1 GET https://vicktor61.github.io/VickTor61/indecision-sniffle.git/static/js/2.ed9a5867.chunk.js net::ERR_ABORTED 404
vicktor61.github.io/:1 GET https://vicktor61.github.io/VickTor61/indecision-sniffle.git/static/js/main.0913b291.chunk.js net::ERR_ABORTED 404
/VickTor61/indecision-sniffle.git/manifest.json:1 GET https://vicktor61.github.io/VickTor61/indecision-sniffle.git/manifest.json 404
manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.

我了解问题可能是因为 gh-pages 服务器无法获取我的文件。但我仍然不知道为什么。请我非常感谢详细的回复。

这是我的应用链接 https://vicktor61.github.io/indecision-sniffle/

这是我的 package.json 文件

{
  "homepage": "https://github.com/VickTor61/indecision-sniffle.git",
  "name": "indecision-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "axios": "^0.21.1",
    "gh-pages": "^3.2.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-modal": "^3.14.3",
    "react-scripts": "4.0.3",
    "uniqid": "^5.3.0",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "yarn run build",
    "deploy": "gh-pages -d build"
  },
  "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"
    ]
  }
}

这是我托管整个应用程序的 github 页面 https://github.com/VickTor61/indecision-sniffle/

【问题讨论】:

标签: reactjs google-chrome github github-pages


【解决方案1】:

根据 github 页面上的错误猜测,该页面正在尝试加载无法找到的文件。我会说你的主页是错误的。不应该

"homepage": "https://github.com/VickTor61/indecision-sniffle.git",

应该是

"homepage": "https://vicktor61.github.io/indecision-sniffle",

当页面尝试加载这个文件时

https://vicktor61.github.io/VickTor61/indecision-sniffle.git/static/css/main.aea680b0.chunk.css

应该是这个文件

https://vicktor61.github.io/indecision-sniffle/static/css/main.aea680b0.chunk.css

【讨论】:

【解决方案2】:

根据官方docs,在package.json 中设置homepage 设置如下应该可以解决问题:

"homepage": ".",

docs 中写道:

这将确保所有资产路径都相对于 索引.html。然后,您将能够将您的应用程序从 http://mywebsite.comhttp://mywebsite.com/relativepath 甚至 http://mywebsite.com/relative/path 无需重建。

【讨论】:

    猜你喜欢
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 2021-05-15
    • 2019-04-27
    相关资源
    最近更新 更多