gatsbyjs/gatsby · error

Could not find "gatsby" in ${rootPath}. Perhaps it wasn't in

Error message

Could not find "gatsby" in ${rootPath}. Perhaps it wasn't installed properly?

What it means

Thrown by `resolveGatsbyPath` in create-gatsby (install-plugins.ts:16). It calls `requireResolve('gatsby/package.json', { paths: [rootPath] })`; if that throws (module not found) or returns falsy, the catch block rethrows this message. It signals that the freshly scaffolded project does not have `gatsby` resolvable from its root.

Source

Thrown at packages/create-gatsby/src/install-plugins.ts:16

import { reporter } from "./utils/reporter"
import path from "path"
import { PluginConfigMap } from "."
import { requireResolve } from "./utils/require-utils"

const resolveGatsbyPath = (rootPath: string): string | never => {
  try {
    const gatsbyPath = requireResolve(`gatsby/package.json`, {
      paths: [rootPath],
    })

    if (!gatsbyPath) throw new Error()

    return gatsbyPath
  } catch (e) {
    throw new Error(
      `Could not find "gatsby" in ${rootPath}. Perhaps it wasn't installed properly?`
    )
  }
}

const resolveGatsbyCliPath = (
  rootPath: string,
  gatsbyPath: string
): string | never => {
  try {
    let installPluginCommand
    try {
      installPluginCommand = requireResolve(
        `gatsby-cli/lib/handlers/plugin-add`,
        {
          // Try to find gatsby-cli in the site root, or in the site's gatsby dir
          paths: [rootPath, path.dirname(gatsbyPath)],
        }

View on GitHub (pinned to 8b06340921)

Solutions

  1. Run `npm install` (or `yarn` / `pnpm install`) in rootPath and retry.
  2. Delete node_modules and the lockfile, then reinstall.
  3. Verify `require('gatsby/package.json')` resolves from rootPath in a quick script.
  4. Check the rootPath passed to install-plugins is the project root.

Example fix

# before — gatsby not installed
create-gatsby  # then immediately invoke plugin install

# after
npm install
# then re-run plugin install
Defensive patterns

Strategy: validation

Validate before calling

function gatsbyIsResolvableFrom(rootPath) {
  try { return Boolean(require.resolve(require.resolve('gatsby/package.json', { paths: [rootPath] }))) }
  catch { return false }
}

Type guard

function canResolveGatsby(rootPath) {
  try { require.resolve('gatsby/package.json', { paths: [rootPath] }); return true }
  catch { return false }
}

Try / catch

try {
  resolveGatsbyPath(rootPath)
} catch (e) {
  if (/Could not find "gatsby"/.test(e.message)) {
    // run npm install then retry
  } else throw e
}

Prevention

When it happens

Trigger: Running `create-gatsby` plugin install before `npm install`/`yarn` has placed gatsby in node_modules; a failed or interrupted install; a monorepo where gatsby is hoisted elsewhere and not resolvable from rootPath; corrupted node_modules.

Common situations: Interrupting `npm install`; using a custom package manager that did not link gatsby; running install-plugins against the wrong rootPath; lockfile conflicts leaving gatsby uninstalled.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/0346bd1911e226fc. Report an issue: GitHub.