Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React on Github Pages: gh-pages package not working

Problem

I am trying to put my React app on github pages. However, I can't even deploy the app to GitHub pages.

My Setup

I am using Visual Studio Code on my Windows 10 machine. I created my React app with create-react-app. I followed this tutorial to set up my app for Github Pages. This is my package.json:

{
  "homepage": "https://MisturDust319.github.io/ign_code_foo",
  "name": "ign_code_foo",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "bootstrap": "^4.1.0",
    "gh-pages": "^1.1.0",
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-scripts": "1.1.4",
    "reactstrap": "^5.0.0-beta.3"
  },
  "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": {}
}

The full source is available here

What I've Done

To deploy, you are supposed to just run

npm run deploy

However, when I enter that command, from Windows PowerShell, Git Bash, and the Command Prompt, I just get several variations of "command not found".

In response, I uninstalled gh-pages from dev-dependencies and reinstalled it as a normal dependency. No change. At this point, I've exhausted all solutions I can think of, and Google has only pulled up people who didn't include the deploy command in package.json.

like image 875
MisturDust319 Avatar asked Apr 15 '18 18:04

MisturDust319


3 Answers

You need to install gh-pages globally by adding "-g":

npm install -g gh-pages --save-dev

and then

npm run deploy

Docs: https://devdocs.io/npm/getting-started/installing-npm-packages-globally

like image 102
Captone Habiyaremye Avatar answered Nov 15 '22 17:11

Captone Habiyaremye


You need install gh-pages before running deploy, run:

npm install --save-dev gh-pages then npm run deploy

like image 21
PCampello Avatar answered Nov 15 '22 16:11

PCampello


I cannot add a comment to this post, because I don't have enough score. But there is an error in the your package.json code:

 "deploy:": "gh-pages -d build"

Because, there is an extra semicolon :. It should be:

"deploy": "gh-pages -d build"
like image 42
catra Avatar answered Nov 15 '22 17:11

catra