{"record":{"id":"0346bd1911e226fc","repo":"gatsbyjs/gatsby","slug":"could-not-find-gatsby-in-rootpath-perhaps-it","errorCode":null,"errorMessage":"Could not find \"gatsby\" in ${rootPath}. Perhaps it wasn't installed properly?","messagePattern":"Could not find \"gatsby\" in (.+?)\\. Perhaps it wasn't installed properly\\?","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/create-gatsby/src/install-plugins.ts","lineNumber":16,"sourceCode":"import { reporter } from \"./utils/reporter\"\nimport path from \"path\"\nimport { PluginConfigMap } from \".\"\nimport { requireResolve } from \"./utils/require-utils\"\n\nconst resolveGatsbyPath = (rootPath: string): string | never => {\n  try {\n    const gatsbyPath = requireResolve(`gatsby/package.json`, {\n      paths: [rootPath],\n    })\n\n    if (!gatsbyPath) throw new Error()\n\n    return gatsbyPath\n  } catch (e) {\n    throw new Error(\n      `Could not find \"gatsby\" in ${rootPath}. Perhaps it wasn't installed properly?`\n    )\n  }\n}\n\nconst resolveGatsbyCliPath = (\n  rootPath: string,\n  gatsbyPath: string\n): string | never => {\n  try {\n    let installPluginCommand\n    try {\n      installPluginCommand = requireResolve(\n        `gatsby-cli/lib/handlers/plugin-add`,\n        {\n          // Try to find gatsby-cli in the site root, or in the site's gatsby dir\n          paths: [rootPath, path.dirname(gatsbyPath)],\n        }","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/create-gatsby/src/install-plugins.ts#L1-L34","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `npm install` (or `yarn` / `pnpm install`) in rootPath and retry.","Delete node_modules and the lockfile, then reinstall.","Verify `require('gatsby/package.json')` resolves from rootPath in a quick script.","Check the rootPath passed to install-plugins is the project root."],"exampleFix":"# before — gatsby not installed\ncreate-gatsby  # then immediately invoke plugin install\n\n# after\nnpm install\n# then re-run plugin install","handlingStrategy":"validation","validationCode":"function gatsbyIsResolvableFrom(rootPath) {\n  try { return Boolean(require.resolve(require.resolve('gatsby/package.json', { paths: [rootPath] }))) }\n  catch { return false }\n}","typeGuard":"function canResolveGatsby(rootPath) {\n  try { require.resolve('gatsby/package.json', { paths: [rootPath] }); return true }\n  catch { return false }\n}","tryCatchPattern":"try {\n  resolveGatsbyPath(rootPath)\n} catch (e) {\n  if (/Could not find \"gatsby\"/.test(e.message)) {\n    // run npm install then retry\n  } else throw e\n}","preventionTips":["Run the package manager install before invoking install-plugins.","Verify node_modules is intact (no partial installs).","Pass the correct project rootPath."],"tags":["create-gatsby","install","npm","module-resolution"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}