reactjs - 将反应站点发布到 github.io 时出错
问题描述
我正在尝试将我的反应站点发布到 github 页面。(网址:https ://kumarsreenivas051.github.io/kumar-site/ )
我将代码直接提交到 Github 的 master 分支。
我的 package.json 包含:
{
"name": "kumar-site",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.11.4",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.8.3",
"gh-pages": "^2.2.0",
"react": "^17.0.2",
"react-bootstrap-validation": "^0.1.11",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.1"
},
"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"
]
},
"homepage": "https://kumarsreenivas051.github.io/kumar-site"
}
当我尝试跑步时gh-pages -d build
得到错误。日志显示:
14 verbose lifecycle kumar-site@0.1.0~deploy: CWD: C:\Users\Kumaraswamy V S\Documents\GitHub\kumarsreenivas051.github.io\kumar-site
15 silly lifecycle kumar-site@0.1.0~deploy: Args: [ '/d /s /c', 'gh-pages -d build' ]
16 silly lifecycle kumar-site@0.1.0~deploy: Returned: code: 1 signal: null
17 info lifecycle kumar-site@0.1.0~deploy: Failed to exec deploy script
18 verbose stack Error: kumar-site@0.1.0 deploy: `gh-pages -d build`
18 verbose stack Exit status 1
18 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
18 verbose stack at EventEmitter.emit (events.js:315:20)
18 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
18 verbose stack at ChildProcess.emit (events.js:315:20)
18 verbose stack at maybeClose (internal/child_process.js:1048:16)
18 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
19 verbose pkgid kumar-site@0.1.0
20 verbose cwd C:\Users\Kumaraswamy V S\Documents\GitHub\kumarsreenivas051.github.io\kumar-site
21 verbose Windows_NT 10.0.19043
22 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "deploy"
23 verbose node v14.16.0
24 verbose npm v6.14.11
25 error code ELIFECYCLE
26 error errno 1
27 error kumar-site@0.1.0 deploy: `gh-pages -d build`
27 error Exit status 1
28 error Failed at the kumar-site@0.1.0 deploy script.
28 error This is probably not a problem with npm. There is likely additional logging output above.
29 verbose exit [ 1, true ]
我该怎么做才能成功发布站点?
仅供参考:使用的操作系统是 Windows 10 64 位
解决方案
我在https://github.com/kumarsreenivas051/kumarsreenivas051.github.io中只看到一个分支
因此,要正确执行gh-pages
脚本,您可能需要指定分支。
调整您的package.json
脚本以将部署推送到 main:
"scripts": {
"predeploy": "npm run build",
- "deploy": "gh-pages -d build",
+ "deploy": "gh-pages -b main -d build",
推荐阅读
- c# - 是否有一种 LINQ 方式可以将相同的字符 n 次附加到字符串中?
- c# - c# 从 GNU objcopy 进程中捕获原始数据,然后转储到文件中
- javascript - Kendo UI 网格 - 更改选定的行并通过箭头键展开/折叠组
- java - 如何在关闭活动后立即从活动中删除数据
- puppeteer - Puppeteer-extra 允许 Flash 支持
- c - GetWindowTextLength() 返回 0,可能是因为无效的窗口句柄
- php - 使用ajax插入复选框数组
- python - 大熊猫的双边 t 检验
- javascript - 如何描述一个可以正确序列化的值?
- html - 如何在链接弹簧启动/角度应用程序中获取 th:href="@{}" 而不是 href=""