Giter Club home page Giter Club logo

react-gh-pages's Introduction

Deploying a React App* to GitHub Pages

* created using create-react-app

Introduction

In this tutorial, I'll show you how you can create a React app and deploy it to GitHub Pages.

To create the React app, I'll be using create-react-app, which is a tool people can use to create a React app from scratch. To deploy the React app, I'll be using gh-pages, which is an npm package people can use to deploy things to GitHub Pages, a free web hosting service provided by GitHub.

If you follow along with this tutorial, you'll end up with a new React app—hosted on GitHub Pages—which you can then customize.

Translations

This tutorial has been translated from its original English into the following languages:

Tutorial

Prerequisites

  1. Node and npm are installed. Here are the versions I'll be using while making this tutorial:

    $ node --version
    v16.13.2
    
    $ npm --version
    8.1.2

    Installing npm adds two commands to the system—npm and npx—both of which I'll be using while making this tutorial.

  2. Git is installed. Here's the version I'll be using while making this tutorial:

    $ git --version
    git version 2.29.1.windows.1
  3. A GitHub account. :octocat:

Procedure

1. Create an empty repository on GitHub

  1. Sign into your GitHub account.
  2. Visit the Create a new repository form.
  3. Fill in the form as follows:
    • Repository name: You can enter any name you want*.

      * For a project site, you can enter any name you want. For a user site, GitHub requires that the repository's name have the following format: {username}.github.io (e.g. gitname.github.io)

      The name you enter will show up in a few places: (a) in references to the repository throughout GitHub, (b) in the URL of the repository, and (c) in the URL of the deployed React app.

      In this tutorial, I'll be deploying the React app as a project site.

      I'll enter: react-gh-pages

    • Repository privacy: Select Public (or Private*).

      * For GitHub Free users, the only type of repository that can be used with GitHub Pages is Public. For GitHub Pro users (and other paying users), both Public and Private repositories can be used with GitHub Pages.

      I'll choose: Public

    • Initialize repository: Leave all checkboxes empty.

      That will make it so GitHub creates an empty repository, instead of pre-populating the repository with a README.md, .gitignore, and/or LICENSE file.

  4. Submit the form.

At this point, your GitHub account contains an empty repository, having the name and privacy type that you specified.

2. Create a React app

  1. Create a React app named my-app:

    In case you want to use a different name from my-app (e.g. web-ui), you can accomplish that by replacing all occurrences of my-app in this tutorial, with that other name (i.e. my-app --> web-ui).

    $ npx create-react-app my-app

    That command will create a React app written in JavaScript. To create one written in TypeScript, you can issue this command instead:

    $ npx create-react-app my-app --template typescript

    That command will create a new folder named my-app, which will contain the source code of a React app.

    In addition to containing the source code of the React app, that folder is also a Git repository. That characteristic of the folder will come into play in Step 6.

    Branch names: master vs. main

    The Git repository will have one branch, which will be named either (a) master, the default for a fresh Git installation; or (b) the value of the Git configuration variable, init.defaultBranch, if your computer is running Git version 2.28 or later and you have set that variable in your Git configuration (e.g. via $ git config --global init.defaultBranch main).

    Since I have not set that variable in my Git installation, the branch in my repository will be named master. In case the branch in your repository has a different name (which you can check by running $ git branch), such as main; you can replace all occurrences of master throughout the remainder of this tutorial, with that other name (e.g. mastermain).

  2. Enter the newly-created folder:

    $ cd my-app

At this point, there is a React app on your computer and you are in the folder that contains its source code. All of the remaining commands shown in this tutorial can be run from that folder.

3. Install the gh-pages npm package

  1. Install the gh-pages npm package and designate it as a development dependency:

    $ npm install gh-pages --save-dev

At this point, the gh-pages npm package is installed on your computer and the React app's dependence upon it is documented in the React app's package.json file.

4. Add a homepage property to the package.json file

  1. Open the package.json file in a text editor.

    $ vi package.json

    In this tutorial, the text editor I'll be using is vi. You can use any text editor you want; for example, Visual Studio Code.

  2. Add a homepage property in this format*: https://{username}.github.io/{repo-name}

    * For a project site, that's the format. For a user site, the format is: https://{username}.github.io. You can read more about the homepage property in the "GitHub Pages" section of the create-react-app documentation.

    {
      "name": "my-app",
      "version": "0.1.0",
    + "homepage": "https://gitname.github.io/react-gh-pages",
      "private": true,

At this point, the React app's package.json file includes a property named homepage.

5. Add deployment scripts to the package.json file

  1. Open the package.json file in a text editor (if it isn't already open in one).

    $ vi package.json
  2. Add a predeploy property and a deploy property to the scripts object:

    "scripts": {
    +   "predeploy": "npm run build",
    +   "deploy": "gh-pages -d build",
        "start": "react-scripts start",
        "build": "react-scripts build",

At this point, the React app's package.json file includes deployment scripts.

6. Add a "remote" that points to the GitHub repository

  1. Add a "remote" to the local Git repository.

    You can do that by issuing a command in this format:

    $ git remote add origin https://github.com/{username}/{repo-name}.git

    To customize that command for your situation, replace {username} with your GitHub username and replace {repo-name} with the name of the GitHub repository you created in Step 1.

    In my case, I'll run:

    $ git remote add origin https://github.com/gitname/react-gh-pages.git

    That command tells Git where I want it to push things whenever I—or the gh-pages npm package acting on my behalf—issue the $ git push command from within this local Git repository.

At this point, the local repository has a "remote" whose URL points to the GitHub repository you created in Step 1.

7. Push the React app to the GitHub repository

  1. Push the React app to the GitHub repository

    $ npm run deploy

    That will cause the predeploy and deploy scripts defined in package.json to run.

    Under the hood, the predeploy script will build a distributable version of the React app and store it in a folder named build. Then, the deploy script will push the contents of that folder to a new commit on the gh-pages branch of the GitHub repository, creating that branch if it doesn't already exist.

    By default, the new commit on the gh-pages branch will have a commit message of "Updates". You can specify a custom commit message via the -m option, like this:

    $ npm run deploy -- -m "Deploy React app to GitHub Pages"

At this point, the GitHub repository contains a branch named gh-pages, which contains the files that make up the distributable version of the React app. However, we haven't configured GitHub Pages to serve those files yet.

8. Configure GitHub Pages

  1. Navigate to the GitHub Pages settings page
    1. In your web browser, navigate to the GitHub repository
    2. Above the code browser, click on the tab labeled "Settings"
    3. In the sidebar, in the "Code and automation" section, click on "Pages"
  2. Configure the "Build and deployment" settings like this:
    1. Source: Deploy from a branch
    2. Branch:
      • Branch: gh-pages
      • Folder: / (root)
  3. Click on the "Save" button

That's it! The React app has been deployed to GitHub Pages! 🚀

At this point, the React app is accessible to anyone who visits the homepage URL you specified in Step 4. For example, the React app I deployed is accessible at https://gitname.github.io/react-gh-pages.

9. (Optional) Store the React app's source code on GitHub

In a previous step, the gh-pages npm package pushed the distributable version of the React app to a branch named gh-pages in the GitHub repository. However, the source code of the React app is not yet stored on GitHub.

In this step, I'll show you how you can store the source code of the React app on GitHub.

  1. Commit the changes you made while you were following this tutorial, to the master branch of the local Git repository; then, push that branch up to the master branch of the GitHub repository.

    $ git add .
    $ git commit -m "Configure React app for deployment to GitHub Pages"
    $ git push origin master

    I recommend exploring the GitHub repository at this point. It will have two branches: master and gh-pages. The master branch will contain the React app's source code, while the gh-pages branch will contain the distributable version of the React app.

References

  1. The official create-react-app deployment guide
  2. GitHub blog: Build and deploy GitHub Pages from any branch
  3. Preserving the CNAME file when using a custom domain

Notes

  • Special thanks to GitHub (the company) for providing us with the GitHub Pages hosting service for free.
  • And now, time to turn the default React app generated by create-react-app into something unique!
  • This repository consists of two branches:
    • master - the source code of the React app
    • gh-pages - the React app built from that source code

Contributors

Thanks to these people for contributing to the maintenance of this tutorial.

gitname rhulse AbhishekCode adnjoo thebeatlesphan valerio-pescatori jackweyhrich

This list is maintained manually—for now—and includes (a) each person who submitted a pull request that was eventually merged into master, and (b) each person who contributed in a different way (e.g. providing constructive feedback) and who approved of me including them in this list.

react-gh-pages's People

Contributors

abhishekcode avatar amitxv avatar dependabot[bot] avatar gitname avatar rhulse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-gh-pages's Issues

fatal: A branch named 'gh-pages' already exists.

I am trying to deploy my app and am getting this error. I have tried running rm -rf node_modules/gh-pages/.cache to no avail. I also tried manually deleting node_modules/gh-pages/.cache and that did not work either.

For troubleshooting, I am on a Mac.

gh-pages white screen

Hi all,
I've been going though some of the solutions that others have put out for this problem without success. I pushed it to the repository via command line.
It seems to not be communicating with anything outside of the dist folder, but if I add the files into the dist folder, I get the same response.
This is a THREE.js project, and it's both my first time working with THREE.js as well as pushing a project to a repository from the command line... So I'm sure there's something I missed along the #way.
2021-12-16

The repository: https://github.com/SlimBloodworth/earth121621

Failed to deploy after failed authentication

gh-pages -d build shows failed authentication due to invalid username or password

` gh-pages -d build

fatal: TypeInitializationException encountered.
The type initializer for 'Microsoft.Alm.Cli.Program' threw an exception.
fatal: TypeInitializationException encountered.
The type initializer for 'Microsoft.Alm.Cli.Program' threw an exception.
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/Nugasnakarmi/OfficeRec.git/'

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] deploy: gh-pages -d build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

How to customize deployment commit message

When I run npm run deploy , it commits to my gh-pages branch with the commit message Updates , which is not very descriptive and I would want to customize, how can I do that?

Change branch to gh-pages in setting

Hello! I have no time to do a pull request with additional instruction step, but I want to notify you about it.

Probably, because initially I tried to add my react project to github pages without gh-pages and only then I found your instruction and used gh-pages as deploy command I had an extra step. So, after using the deploy command in your local project, you need to open the project settings (on the github project repository page) and manually change the source branch on the pages tab, for example from main to the gh-pages branch.

I think it would be nice to add this as note to Step 7

How to push on Github Pages without create-react-app?

I created a React app without create-react-app and I manually configured Webpack. The app is working fine but how do I deploy it on Github pages?
I tried adding the react-scripts dependency and adding the default script that CRA generates, but it is not working. Is there a specific procedure I can follow to do this?

Nothing got published

I have a react project as a sub folder in one repository and I have my gh-pages repo set up and working. I followed the instructions and nothing at all was published to my gh-pages repo. This is the output:


> [email protected] predeploy F:\git\Learning\React\hello
> npm run build


> [email protected] build F:\git\Learning\React\hello
> react-scripts build

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  36.83 KB  build\static\js\2.65aa1cca.chunk.js
  980 B     build\static\js\main.1deb3e49.chunk.js
  770 B     build\static\js\runtime~main.c3b45a10.js
  578 B     build\static\css\main.c6f97728.chunk.css

The project was built assuming it is hosted at /reacthello/.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
To publish it at https://nebosite.github.io/reacthello , run:

  npm run deploy

Find out more about deployment here:

  https://bit.ly/CRA-deploy


> [email protected] deploy F:\git\Learning\React\hello
> gh-pages -d build

Published

Failed to load tsconfig.json: Missing baseUrl in compilerOptions

Hi, I create my react app using this:

create-react-app my-app --scripts-version=react-scripts-ts

When I run yarn deploy I got this error:

yarn run v1.3.2
$ npm run build

> [email protected] build /Users/khuongpham/WebFrontEnd/khuong_website
> react-scripts-ts build

Failed to load tsconfig.json: Missing baseUrl in compilerOptions
Creating an optimized production build...
Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
Starting type checking and linting service...
Using 1 worker with 2048MB memory limit
ts-loader: Using [email protected] and /Users/khuongpham/WebFrontEnd/khuong_website/tsconfig.json
Compiled successfully.

File sizes after gzip:

  35.45 KB  build/static/js/main.60e3476d.js
  300 B     build/static/css/main.29266132.css

The project was built assuming it is hosted at https://khuong.github.io.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

  yarn global add serve
  serve -s build

$ gh-pages -b master -d build
Cloning into 'node_modules/gh-pages/.cache/aHR0cHM6Ly9naXRodWIuY29tL2todW9uZzI5MS9raHVvbmdfd2Vic2l0ZS5naXQ'...
remote: Repository not found.
fatal: repository 'https://github.com/khuong291/khuong_website.git/' not found

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here is my package.json look like:

{
  "name": "khuong_website",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://khuong.github.io",
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-scripts-ts": "2.14.0"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -b master -d build",
    "start": "react-scripts-ts start",
    "build": "react-scripts-ts build",
    "test": "react-scripts-ts test --env=jsdom",
    "eject": "react-scripts-ts eject"
  },
  "devDependencies": {
    "@types/jest": "^22.2.2",
    "@types/node": "^9.6.1",
    "@types/react": "^16.1.0",
    "@types/react-dom": "^16.0.4",
    "gh-pages": "^1.1.0",
    "typescript": "^2.8.1"
  }
}

And my tsconfig.json:

{
  "compilerOptions": {
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true
  },
  "baseUrl": ".",
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ]
}

Deploy failure

I followed the tutorial as verbose as possible. But eventually my app failed to deploy. So this is the log from the cmder command line.

I was able to find a solution. I'll write about it just in a minute.

Failed to deploy after failed login

I setup as the guide suggested. I got through the compile portion and then it asked me to login. I fat fingered the login and now when I try to run again it shows:

> gh-pages -d build

fatal: A branch named 'gh-pages' already exists.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

I cannot see the branch using git branch nor on github. How can I redo this?

Failing to load resource at server root

I am not able to load JSON file in the browser.
Getting the error:

Failed to load /resumeData.json?_=1533629733770:1 resource: the server responded with a status of 404 ()

Please help !!!
Any help would be appreciated.
I am attaching the screenshot of the error!!
screenshot

Problems with react-router-dom

Hi,

first of all, thanks for the good work and that great project. I'm havin major troubles though, using react-router-dom v6 with gh-pages.
As soon as i start using routes, the gh-page just shows a lank screen.

For example this is the App.tsx code

import './App.css';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { Home } from './pages/Home';
import DemonList from './pages/DemonList';

function App() {
	return (
		<div className="App">
			<BrowserRouter basename={process.env.PUBLIC_URL}>
				<Routes>
					<Route path="/" element={<Home />}></Route>
					<Route path="/demons" element={<DemonList />}></Route>
				</Routes>
			</BrowserRouter>
		</div>
	);
}

export default App;

The html source-view at https://oliverzott.github.io/react-gh-page/ is just showing

<head>
    <meta charset="utf-8" />
    <link rel="icon" href="/react-gh-page/favicon.ico" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta name="description" content="Web site created using create-react-app" />
    <link rel="apple-touch-icon" href="/react-gh-page/logo192.png" />
    <link rel="manifest" href="/react-gh-page/manifest.json" />
    <title>React App</title>
    <script defer="defer" src="/react-gh-page/static/js/main.6461c301.js"></script>
    <link href="/react-gh-page/static/css/main.073c9b0a.css" rel="stylesheet">
</head>

<body><noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
</body>

</html>

I tried a lot of suggested fixes and workarounds, but nothing worked so far.

Best regards
Olli

"git-upload-pack" command not found with React v16.4.2

For some reason, once in a blue moon I won't be able to run npm run deploy because when attempting to do "gh-pages -d build" it cannot find git-upload-pack. If I give it a day or two, then come back and try to deploy it works perfectly.

Is there a fix to this? Not sure how to push my React project to github pages when it keeps giving me these errors.

git upload pack

Edit: 8-17-18 @ 1 PM
It seems that my old projects running React v16.4.1 upload perfectly fine. However, my most recent project is using React v16.4.2. Anyone sure if that could be the reason why it isn't working?

npm ERR! code ELIFECYCLE and more...

So, I wanted to add a react website to a seperate github repo and add a github page

I followed the tutorial and everything went well, but the last step didn't:

$ npm run deploy

...
remote: Repository not found.
fatal: repository 'https://github.com/shadow2xx/react-gh-pages.git/' not found

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I checked the log, but this didn't give me more valuable information... I am quite new to react, any suggestions?

Error when deploying

When I execute the npm run deploy, it works but the gh-pages -d build command returns an error::

fatal: unable to access 'https://github.com/(username)/(project).git/': error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

My git version is up to date and I can't find any solution. Can someone helps me ?

How to add a license file to the `gh-pages` branch?

Hello. I've carried out the instructions in your README and was able to deploy my local app to GH pages without issue. I can also edit my app locally, and continue to push those edits to GH pages using npm run deploy, which has worked great so far--thanks for that. But how can I properly add a license file to the gh-pages in GitHub? As a test, I just added one manually, via a commit done within GitHub. After, as a test, I tried to deploy again with npm run deploy. It then displayed this in its output:

error: unable to stat just-written file LICENSE: No such file or directory
fatal: Could not reset index file to revision 'origin/gh-pages'.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\snarl\AppData\Roaming\npm-cache\_logs\2020-02-29T14_15_14_746Z-debug.log

Any ideas on how to troubleshoot/resolve?

React website throw a 404 page not found error on reloading the page.

Whenever I reaload my react website, it throws me page not found error. What I suppose to do? But there is no issue with my other react projects that has been deployed in github.

To push new/updated code to my gthub repo, I write this code ->

  1. git add .
  2. git commit -m "change css"
  3. git push origin master
  4. npm run deploy

What is the problem?

Capture

How to deploy to user or organization website?

Thanks for the detailed and helpful tutorial!

Do you have insights about how to deploy an create-react-app app to an user or organization site? The homepage url would be a bit different. Instead of http://username.github.io/repo-name, the url would be just http://username.github.io?

I'm not sure if gh-pages would still be necessary because there is no more gh-pages branch...?

Is it possible to deploy to my root github.io page?

I wanted to have my root github.io page (e.g. {username}.github.io) as a react app. As you can see, I set my root github io url as the homepage in my package.json when I run gh-pages, I see "published," but my root page is still just displaying the README.md from the create-react-app command.

Thanks for your time

Question: How can I push changes to the gh-pages branch

Hi, I made some code changes to my master branch and pushed the same to the master branch. However my changes do not reflect in the website as the gh-pages still remains unchanged. How to make my changes reflect in gh-pages branch as well so that my website is updated

Suggestion: add instruction for auto-deployment on every git push

First of all, thanks for the clear instructions!

Now that we have GitHub Actions as a CI service, the next logical step after reading your instructions is to integrate this with GH Actions, so that every time I push my code to github on master, it would automatically build and deploy gh-pages

Errors running NPM commands after posting React app to github pages.

Everything was working before deploying to github pages, and the first deploy worked no problem. But ever since, now when running any NPM commands in the project, I'm getting this set of errors:

geekcentric => npm start
npm ERR! file /mnt/c/Users/GeekCentric/Documents/ReactJS/the_app/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token / in JSON at position 611 while >parsing near '...": "^1.2.0"
npm ERR! JSON.parse }
npm ERR! JSON.parse }
npm ERR! JSON.parse
npm ERR! JSON.parse
npm ERR! JSON.parse // geekcentric => np...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just >JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/geekcentric/.npm/_logs/2018-09-11T00_38_07_636Z->debug.log

The error is in my package.json file but I can't find anything that would throw the error or what's going wrong.

{
  "name": "theapp",
  "version": "0.1.0",
  "private": true,
  "homepage": "http://me.github.io/theapp",
  "dependencies": {
    "axios": "^0.18.0",
    "firebase": "^5.4.2",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-router-dom": "^4.3.1",
    "react-scripts": "1.1.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },
  "devDependencies": {
    "gh-pages": "^1.2.0"
  }
}

I'm using the create-react-app and the gh-pages npm module. Any help would be very appreciated

Error during build process (`events.js:174` ... `throw er; // Unhandled 'error' event`)

Installed gh-pages as dev dependency in my react project. The below error is displayed everytime I run the command npm run deploy to deploy the app to github using gh-pages.

Error:

[email protected] deploy C:\Users\Ahmed Khan\Development Projects\Reactjs Projects\sample-react-deploy
> gh-pages -d build

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: spawn git ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Ahmed Khan\AppData\Roaming\npm-cache\_logs\2020-06-30T11_24_22_821Z-debug.log

My package.json file:

{
  "homepage": "https://ahmedgulabkhan.github.io/sample-react-deploy",
  "name": "sample-react-deploy",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "^3.4.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"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "gh-pages": "^3.1.0"
  }
}

Searched for some help online, and downgraded react-scripts to version 2.1.8. But the issue is still not resolved.

Can I change the GitHub 'default' branch without affecting `npm run deploy`?

Hello. I should first say that for a side project, I used create-react-app to build a simple React app locally. I then used the instructions in this repo to push my app to GitHub pages. The instructions were very clear, and worked perfectly on the first try--no hassle at all--amazing. So thanks very much for that.

I have a question though. Can I safely change the 'default' branch in my GitHub settings (screenshot) without it affecting npm run deploy? Here is more info on that.

I did indeed carry out all your instructions, including step 8. The GitHub repo for my app can be seen here: https://github.com/cagross/react-specials As you described, the GitHub repo has is both a master branch and a gh-pages branch. Separately, I continue to develop my app locally, and periodically push my edits to GitHub pages, using npm run deploy.

In the GitHub repo, the 'default' branch seems to have been automatically set to gh-pages. I would like to change it to master (screenshot). Does npm run deploy require that the GitHub 'default' branch be set to gh-pages? Or can I safely change the GitHub 'default' branch to master without it affecting npm run deploy?

Maybe a more precise question is: to what GitHub branch does npm run deploy push edits? Does it push edits to the gh-pages branch, regardless of what I have set for the 'default' branch in my GitHub settings? Or does npm run deploy push edits to whatever branch I have set as 'default' in my GitHub settings?

I think I can change the GitHub 'default' branch without affecting npm run deploy. npm run deploy will push to whatever remote branch I have configured in my local Git repo--correct? If so, whatever I have set as 'default' branch in my GitHub settings doesn't matter. Am I on the right track there?

The reason I’d like to change the GitHub 'default' branch to master is because the master branch is the branch that actually displays the code I wrote, as well as the README file for the GitHub repo. So I'd like to share a link to this repo with collaborators/potential employers, and have my code/README file displayed by default (rather than forcing them to change the branch to master). I realize I can share a direct link to the master branch, and I'll do that as a fall back.

Thanks.

Page not found

I've done according your instruction, but everything is pushed to github repo but nothing to github pages. I added "homepage":"..." to package.json, and got nothing. But my terminal said

im@im:~/Desktop/figma-app$ npm run deploy

> [email protected] predeploy /home/im/Desktop/figma-app
> npm run build


> [email protected] build /home/im/Desktop/figma-app
> react-scripts build

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  39.39 KB  build/static/js/2.a88a2725.chunk.js
  777 B     build/static/js/runtime-main.a0ad3164.js
  648 B     build/static/js/main.e84e2243.chunk.js
  556 B     build/static/css/main.d1b05096.chunk.css

The project was built assuming it is hosted at /figma/.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.

Find out more about deployment here:

  bit.ly/CRA-deploy


> [email protected] deploy /home/im/Desktop/figma-app
> gh-pages -d build

Username for ...
Password for ... 
Published

Blank Page Load

Hi gitname -

Troubleshooted my way through your tutorial, thanks in advance for the help. Ran into an issue in that the page that loads is simply blank and white, although it does load the <title> correctly from my index.html. any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.