1

I'm trying to deploy my Gatsby site to GitHub pages. I've followed all the instructions in this tutorial: Gatsby GHPages Tutorial. Setting up my gh-pages branch and adding the path prefix and script deploy command.

However, when I run npm run deploy everything goes fine at first but eventually, the process seems to hang at info Done Building in 22 sec. I've also attached a screenshot of my logs after running the command. Please let me know if there is any more information I should provide to help me solve this problem. Thanks in advance!

npm run deploy log

Will Rowe
  • 71
  • 8

2 Answers2

2

Make sure the deploy command is..
"deploy": "gatsby build --prefix-paths && gh-pages -d public",

Move the README.md from the root directory or delete it.

Create an index.html file and add <meta http-equiv="Refresh" content="2; url=public/index.html"> to it. mentioned here.

Execute npm run deploy which should result in "Published" at EOF.

Change the branch from master to gh-pages in the repo settings.

A Webb
  • 633
  • 1
  • 8
  • 16
  • Just tried that. So the full command was now: `gatsby build --prefix-paths && gh-pages -d public -b master` and have the same issue still. And my pathPrefix matches the repo name. – Will Rowe Sep 02 '20 at 21:23
  • I apologize for getting back with you so late. Does the master branch already exist? "Note: to select master or gh-pages as your publishing source, you must have the branch present in your repository." Also, post the link of the repository and I will try to publish a version of it myself. – A Webb Sep 03 '20 at 01:24
  • No worries, appreciate the help. I've tried everything at this [link](https://github.com/transitive-bullshit/react-modern-library-boilerplate/issues/15) and here's the repo [link](https://github.com/willjrowe/IR-Plan-Site). At this point I just have the `master` branch because I'm just trying to get anything to work haha – Will Rowe Sep 03 '20 at 02:40
  • What I would really like is some output from the hanging process but I don't quite understand how to set NODE_DEBUG see [link](https://www.npmjs.com/package/gh-pages#debugging) – Will Rowe Sep 03 '20 at 02:59
  • Hey @WillRowe I was able to get it to publish but it is only displaying the README. Let me fix it really quick and then I will get back with you. – A Webb Sep 03 '20 at 15:01
  • @WillRowe I updated the answer and created a pull request to your repo. Let me know if you have any other issues - @ me if so, I do not have notifications enabled otherwise. – A Webb Sep 03 '20 at 15:20
  • @WillRowe any updates on this? I'm currently dealing with the same issue. – Diego Fortes Nov 14 '20 at 23:53
2

In my particular case what solved the issue was:

  • Globally installing gh-pages with yarn global add gh-pages
  • Updating my deploy script to:
  "scripts": {
    "deploy": "gatsby build --prefix-paths && gh-pages -d public -b gh-pages"
  },
  • If you have a dev branch make sure that you are on it. Merge with the master if necessary and deploy from inside the dev. git push origin dev
  • Create an index.html file at the root of the project and add <meta http-equiv="Refresh" content="2; url=public/index.html"> as aforementioned by @A Webb.

It ended up looking like this:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Refresh" content="2; url=public/index.html">
</head>

<body>

</body>

</html>

Please keep in mind that once you run npm run deploy it may look like it's stuck but it takes some time, at least in my case it did. You'll know it's finished once it says "Published".

Gatsby published

Just for the sake of testing I'd wait around 30 minutes depending on the size of your website.

Diego Fortes
  • 8,830
  • 3
  • 32
  • 42