score:7
Since I spent two hours to solve this problem and I had to get this information from multiple sources and solutions, I decided to spend another hour to write this post here for other future deployers (!) facing the same issues.
To provide context, For each account, GitHub allows hosting 1 personal static webpage and numerous static project webpages on GitHub Pages for free.
To use this functionality, you must change the repository name to {github-username}.github.io
for the personal page and {github-username}.github.io/{project-name}
for any projects you want to deploy to GitHub Pages.
This question and answer are about the personal page only, but might give some insights for debugging the project pages as well. Tutorials for deploying a react project using npm
can be found online (e.g., see this post).
To fix the freezing problem, someone suggested that you change the deploy command to the following:
"scripts": { ... "predeploy": "npm run build", "deploy": "gh-pages -b master -d build" },
Adding -b master
specifies the branch your project will be deployed to. This helps avoid the terminal freezing and your code actually gets deployed and accessed via www.{github-username}.github.io/
, but all the build file information will be committed and pushed to the master branch.
What I wanted to do was having the source project on the master branch and having the deployed website on a different build branch. But also, I did not want the URL to include the branch name as well.
I tried changing -b master
to -b {deploy-branch=name}
, e.g., -b gh-pages
where gh-pages
is the name of the branch I'd like to deploy my website to. This caused running npm run deploy
to freeze again!!
To solve this problem, I had to manually create a remote branch, called gh-pages
and run the deploy command again.
- To make sure the GitHub pages will be loaded from the
gh-pages
branch, I had to go to my GitHub repository > Settings > GitHub Pages and change the branch togh-pages
(see image below).
After step 2, my website was up and running and could be accessed via www.{github-username}.github.io/
.
You can go ahead and push your project commits to the branch master as well. Doing this, of course, will not affect your build and GitHub personal page.
- The last problem is avoiding the error "Branch gh-pages already exists" after using
CTRL+C
to terminate the unresponsive terminal.
The solution is removing the cache, but since version 3.1 of gh-pages node_module
, they moved the cache to a different path. So instead of:
rm -rf node_modules/gh-pages/.cache
, I used:
rm -rf node_modules/.cache/gh-pages
to avoid the error (thanks to Nicholas for his comment).
I hope this helps other people as well :)
Source: stackoverflow.com
Related Query
- How to deploy react app to Github pages for personal page
- How do I deploy my react app to GitHub Pages in production mode?
- GitHub Pages Page Not Found for React App
- GitHub pages link returns blank page for React app
- How do i deploy a React app to Github Pages from Github Actions?
- How can I deploy react app on github pages?
- How to deploy a react app that does not have index.html on an apache server for production
- How do I deploy a simple React app as a "user page" to Github Pages?
- How to deploy a React App for each PR in a different URL on Azure?
- How do I deploy an react app to azure and change the default page
- React App renders blank page on Github Pages
- React app deployment on github pages shows a blank page
- How to create routing for multi page app in react
- How to create _redirects file for React JS app to deploy it on Netlify
- how to deploy react app with github gh-pages
- GitHub pages returning error 304 for react app
- How do I add an HTML page for template tags when I am using Routes to display web app pages
- How do I host my React app on Github pages without getting redirected?
- First Page of React App Blank when deployed using github pages
- How To Use A React Page For a Github Domain Page
- React App just shows the starting page on Github pages
- How to create multiple page app using react
- How to deploy a React App on Apache web server
- How to deploy a react app on cPanel?
- How to set headers for a React app created using 'create-react-app'
- How do I configure my .htaccess file for React App in Subdirectory?
- Github pages still shows README after deploying React app
- How to reload a page (state) in a react app
- How to change default localhost port for React App
- how to make webpack typescript react webpack-dev-server configuration for auto building and reloading page
More Query from same tag
- Understanding combineReducers
- Handling Null Object Property Value in Component
- combine extraReducers with exact same code with redux toolkit
- React backgroundImage inline style not working
- How to fetch input from text box and print in React?
- MUI BottomNavigation is not sticky by default
- Multiple selected values of React material-ui Autocomplete?
- TypeError when accessing window.google on Next.js
- Handling Interval with onMouseEnter/onMouseLeave
- react filtering an object of arrays
- Uncaught TypeError: data.map is not a function -->react component error
- Why does setTimeout return a number instead of text? ReactJS
- can not assign new property in react , got ` can't add property yyy, object is not extensible`
- Flexbox cannot center text because of padding
- How to unit test React JSX ES6 code with KARMA?
- whanted to hide and show the opacity the methods is not working?
- Where am i going wrong with using typescript and redux to retrieve the stores data?
- one of my controllers is not rendering when I update the store
- Which renders first child or parent in reactjs
- How to user useState hooks on different instances?
- How to display specific img on li hover without get request in react?
- How to hide my source code from inspect element/sources?
- Draggable Item from component A to B
- I have a icon within the button , I want that when user click that icon the button disapper in other words it shoulb not be visible anymore
- VScode messes JSX format (beautify)
- Could not type any text inside textfield
- Axios: Using baseUrl in a separate file causes problems with setting authentication token in axios request headers
- reactjs OR condition breaks in the second comparison
- Why my images don't loading in the my page?
- Passing data from parent to child reactjs?