繁体   English   中英

React - 我无法使用 npm 运行部署部署到 github

[英]React - I can't deploy to github with npm run deploy

首先,我创建了存储库。 然后我什么时候到终端并输入git init ,然后git add. , and then I took these commands from github and pasted in terminal: git commit -m "first commit" git branch -M main git remote add origin https://githubl.com/igora45/ReactShoppingEcommerce.git git push -u origin main

然后我安装了: npm i gh-pages --save-dev 然后我转到我的package.json文件并放置"homepage": "https://igora45.github.io/ReactShoppingEcommerce" ,然后在package.json的“脚本”中,我仍然"predeploy": "npm run build", "deploy": "gh-pages -d build",

然后,转到终端并输入git add. , git commit -m "deploy" ,然后git push ,最后npm run deploy

我正在尝试使用npm run deploy我的 React 应用程序部署到 github,自从我尝试解决此问题 20 小时后这就无法正常工作

我的package.json PACKAGE.JSON

在我的终端中,当我写npm run deploy时: TERMINAL

我的文件夹和文件

我试图从我的.gitignore中删除“dist”和“dist-ssr”,但我无法解决这个问题。 我在 package.json 的scripts中添加了"heroku-postbuild": "cd client && npm install && npm run build" ,但仍然无法正常工作。

我也尝试部署到 .netlify,但出现了几个错误。

当您说gh -d build时,这意味着您要部署build文件夹。
但我看到您的 output 文件夹是dist而不是build
尝试将其更改为gh-pages -d dist

还要检查您是否在 GitHub 项目仓库中启用了gh-pages

  1. Go 到settings选项卡
  2. 侧面菜单中的 Select pages选项
  3. 将部署分支设置为gh-pages而不是master

在自定义构建 output 路径上查看此答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM