對前端新手來說

學習git github時,每一個錯誤都要花很多時間理解及排除

下面這篇講解得很清楚如何將React 部署至 GitHub Page

https://rexhung0302.github.io/2021/09/28/20210928/

但如果你像我一樣遇到了問題,不妨參考一下我的經驗:

 

問題1

Failed to get remote.origin.url (task must either be run in a git repository with a configured origin remote or must be configured with the "repo" option).

可以先嘗試前輩的方法如下面連結這篇

https://github.com/tschaub/gh-pages/issues/192

看留言對大部分人有效,就是要給他遠端的位置就是了

$字號表示你要在終端機做這件事

$ git remote add origin <url>

<>不用打,url複製這個projectg在github上的位址貼上

截圖 2023-05-28 上午12.38.02

還是不行的話有可能是

問題2

你沒有在reaact 中 安裝 git,檢查git有沒有在package.json裡

沒的話執行

$ npm i git --save

 

問題3

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

如果你的系統是mac,可能會遇到這個問題,把xcode安裝一下

xcode-select --install

然後等它下載安裝完

再次執行

$ npm run build
$ npm run deploy

現在可以去檢查分支出現了沒

 

問題4

fatal: a branch named 'gh-pages' already exists

參自

node_modules/.cache中刪除gh-pages然後運行

$ npm run deploy

 

問題5

fatal: Authentication failed for 'https://github.com/chiumomo/shopee-react.git/'

未得到授權之類獲授權失敗的錯誤碼

授權token生成,看下面這篇,要記得勾選授權動作,再生成token

https://ginnyfahs.medium.com/github-error-authentication-failed-from-command-line-3a545bfd0ca8

得到授權碼以後一定要先複製到其他地方貼上,因為這個token頁面關掉後你們此生不復相見

執行

$ npm run deploy

後Username要放自己的github帳戶名稱(此時刪掉的gh-pages 會再次建立,沒有關係)
底下的password不是要你打密碼,要放上一步得到的token

截圖 2023-05-28 下午9.45.24

token貼上後不會看到任何東西,但是你已經貼上了就請直接enter

截圖 2023-05-28 下午9.48.39

看到published就可以去檢查分支是否成功丟到github上了

截圖 2023-05-28 下午9.51.51

到這裡我真的好感動

來試試開預覽頁面

幹!為什麼還有404

問題7

error404,找不到index.html

截圖 2023-05-28 下午9.52.51

解決方法:把index.html放在homepage最外層(就是不要放在資料夾裡)

成功在github部署後,但是會造成在本地端執行$ npm run start 失敗,

 

這一篇是我的血淚......

有可能你遇到和我不一樣的問題
但是善用搜尋和網頁翻譯一步一步解決終究會到達目的

arrow
arrow

    Cmomo 發表在 痞客邦 留言(0) 人氣()