成功部署到github页面后,我的react应用程序显示为空白



我正在尝试部署一个没有任何路由功能的react应用程序。只要一个页面应用程序到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页面服务器无法获取我的文件。但我还是不知道为什么。请给我详细的答复,我将不胜感激。

这是我的应用程序链接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/

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

"homepage": ".",

文件中指出:

这将确保所有资产路径都相对于index.html。然后您就可以从http://mywebsite.comhttp://mywebsite.com/relativepath或甚至http://mywebsite.com/relative/path而无需重建。

根据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

最新更新