You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gatsby项目部署至GitHub Pages失败求助

Fixing "gh-pages: command not found" When Deploying Gatsby Starter to GitHub Pages

Hey there, let's tackle this deployment error you're hitting. The sh: gh-pages: command not found message tells us that even though gh-pages is listed in your devDependencies, npm can't locate its executable when running the deploy script. Here are a few actionable fixes to try:

1. Reinstall Dependencies to Fix Corrupted Packages

Sometimes node_modules can get messed up during installation. Let's start fresh to ensure all packages are properly set up:

# Delete existing node_modules folder and package lock file
rm -rf node_modules package-lock.json
# Reinstall all project dependencies
npm install

After completing this, run npm run deploy again—this often resolves missing executable issues caused by incomplete or corrupted installs.

2. Use npx to Run gh-pages Directly

If reinstalling doesn't work, the problem might be that npm's script environment isn't picking up the local gh-pages binary. Modify your deploy script in package.json to use npx, which is designed to automatically find and run local npm package binaries:

"deploy": "gatsby build && npx gh-pages -b master -d public"

This bypasses any path-related issues that might be preventing npm from finding the gh-pages command.

3. Verify Your GitHub Pages & Gatsby Configuration

Since you're deploying to your personal GitHub Pages (https://reenaverma.github.io/), double-check these details:

  • Your GitHub repository is named reenaverma.github.io (this is a requirement for personal Pages sites)
  • Your deploy script's -b master flag is correct (personal GitHub Pages use the master branch by default)
  • Your gatsby-config.js keeps pathPrefix: '/' (no extra path segment is needed for a personal Pages site)

4. Move gh-pages to Dependencies (Optional)

While devDependencies should install with a regular npm install, some environments (like CI/CD pipelines) might skip them. If you want to eliminate this as a potential variable, move gh-pages to your main dependencies:

npm install gh-pages --save

This ensures the package is always installed, even in production-focused install modes.

If none of these steps resolve the issue, check the full npm log you referenced (/Users/reenaverma/.npm/_logs/2018-05-30T17_41_52_319Z-debug.log)—it may contain additional context about why the gh-pages command isn't being located.

内容的提问来源于stack exchange,提问作者Reena Verma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:25:25