Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Deploy to GitHub Pages

Truong Minh Nguyen
Truong Minh Nguyen
12,587 Points

Failed at the course-directory@0.1.0 deploy script

Hi guys. After pushing my code to github and configuring the package.json, I tried the script `npm run deploy', the terminal shows the following log:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! course-directory@0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the course-directory@0.1.0 deploy script.

My package.json file is as follows:

{
  "name": "course-directory",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://mrtruongminh.github.io/course-directory",
  "dependencies": {
    "gh-pages": "^2.0.1",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.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": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

2 Answers

J llama
J llama
12,631 Points

Run yarn run build after npm run dreplploy.... and make sure the homepage attribute is set to the same path as the one on github

Alex Vien
Alex Vien
7,615 Points

Hello,

I am having this same issue when i try to run npm deploy build. I get the same error. Can anyone please assist?

Alex Vien
Alex Vien
7,615 Points

For those having this issue... I was able to fix it by navigating to my project directory in the command line and doing

$git remote add origin https://github.com/username/reponame

After doing this, running npm run deploy should work fine.