2025-04-22
2913
#react
Nelson Michael
127590
116
Apr 22, 2025 ⋅ 10 min read

How to deploy React apps to GitHub Pages

Nelson Michael Nelson Michael is a frontend developer from Nigeria. When he's not meddling with CSS, he spends his time writing, sharing what he knows, and playing games.

Recent posts:

move before api

We can finally move elements in the browser with the moveBefore() API

The newly announced moveBefore() API helps developers easily reposition DOM elements while preserving their state.

Chizaram Ken
Apr 22, 2025 ⋅ 8 min read
float ui tutorial

Building responsive websites fast: A Float UI tutorial

Discover Float UI, a set of pre-made templates that leverage the power of Tailwind CSS to help developers create professional websites quickly.

Murat Yüksel
Apr 21, 2025 ⋅ 22 min read
react toastify

React-Toastify (2025 update): Setup, styling & real-world use cases

Learn how to use React-Toastify in 2025, from setup to styling and advanced use cases like API notifications, async toasts, and React-Toastify 11 updates.

Chimezie Innocent
Apr 18, 2025 ⋅ 18 min read
5 Best Open Source Tools For Cross-Browser CSS Testing

5 best open source tools for cross-browser CSS testing

Discover open source tools for cross-browser CSS testing like Playwright and BrowserStack to catch rendering errors, inconsistent styling, and more.

Peter Aideloje
Apr 18, 2025 ⋅ 11 min read
View all posts

15 Replies to "How to deploy React apps to GitHub Pages"

  1. “gh-pages-d build”, there is a space in -d. if you would not add space you can get message that “‘gh-pages-d’ is not recognized as an internal or external command,
    operable program or batch file. ”
    should be like this
    “deploy”: “gh-pages -d build”

  2. Thank you for putting everything very well. I could easily go through the steps and got the deploying done. A big thank you

  3. Hi Michael, thank for posting this. I’m getting an error near the beginning.
    npm install gh-pages –save-dev

    Unsupported engine {
    npm WARN EBADENGINE package: ‘@csstools/[email protected]’,
    npm WARN EBADENGINE required: { node: ‘^14 || ^16 || >=18’ },
    npm WARN EBADENGINE current: { node: ‘v17.9.1’, npm: ‘8.11.0’ }

    I think this is connected to problems I’m having using the command line to manage my repository on github… but maybe I fixed that and this is a new problem…?

    Also, I’d like to subscribe to your blog, but I’m not sure what logrocket is and how to subscribe without paying a membership fee.

  4. When I try this, I end up with an empty page that just says “This site is open source. Improve this page.”

    I looked at the `artifact.zip` file that the ci built, and it appears to have created this index.html with just that content in it at the top level.

    My project runs just fine locally with `npm run start` for example.

    Any idea why this would happen?

    1. In my case I had forgot to add the homepage property in the package.json.

      “In the package.json file, add a homepage property that follows this structure: http://{github-username}.github.io/{repo-name}.”

  5. You don’t need to install the `gh-pages` npm package (or add new script commands for it) if you’re going to use the GitHub Actions workflow file to deploy. You can simply add the workflow file `.github/workflows/deploy.yml` in your project, and GitHub Actions will deploy your website.

    Once I realized this, I uninstalled `gh-pages` from my project and removed the added script entries. I also deleted the `gh-pages` branch from my repo since GitHub Actions doesn’t use the branch to do its deployments. It uses a different technique.

    I think the blog entry can be enhanced to say there are two options to deploy (pick either Option A – gh-pages, or Option B – GH Actions), rather than saying “Install gh-pages first, then add the Actions workflow file too”.

    Also, there are some upgrades and corrections for the workflow file:
    1. Correction: After “- name: Upload artifact” line, add a new line “id: deployment”. (Note: align id with name and uses.)
    2. Upgrade “uses: actions/upload-pages-artifact@v2” to “uses: actions/upload-pages-artifact@v3”.
    3. Upgrade “uses: actions/deploy-pages@v3” to “uses: actions/deploy-pages@v4”

    Regardless, great article. Easy to follow. Keep it up 🙂

Leave a Reply