React应用程序在部署到github页面时返回一个空div



我一直致力于部署我正在github页面上工作的网站,但它似乎在部署时返回一个空div。当与npx serve build一起服务时,它显示所有信息,并且在本地主机上正常显示,但在github页面上部署时仅返回空白div。

部署的步骤:

安装gh-pages
  1. 添加"homepage"package.json
  2. npm run deploy

包。Json代码如下所示,以防出现错误

{
"homepage": "https://jonlev03-hub.github.io/media-pilot/",
"name": "media-pilot",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"gh-pages": "^4.0.0",
"package.json": "^2.0.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"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"
]
},
"devDependencies": {
"github-pages": "^0.1.0"
}
}

如果你在代码块中找不到任何问题,那么网站的所有代码都位于我的存储库github.com/jonlev03-hub/media-pilot。

这是一个与我没有指定路由器使用的baseurl有关的问题。

最新更新