gatsbyjs/gatsby · error
There was a problem loading the local ${command} command. Ga
Error message
There was a problem loading the local ${command} command. Gatsby may not be installed in your site's "node_modules" directory. Perhaps you need to run "npm install"? You might need to delete your "package-lock.json" as well. What it means
Thrown when `resolveCwd.silent` cannot find `gatsby/dist/commands/<command>` (or the legacy `gatsby/dist/utils/<command>`). `isLocalSite` passed (gatsby is declared in `package.json`) but the package is not actually installed under `node_modules`, so the command module cannot be resolved.
Source
Thrown at packages/gatsby-cli/src/create-cli.ts:79
command: string
): ((...args: Array<unknown>) => void) | never {
if (!isLocalSite) {
cli.showHelp()
report.verbose(`current directory: ${directory}`)
return report.panic(
`gatsby <${command}> can only be run for a gatsby site.\n` +
`Either the current working directory does not contain a valid package.json or ` +
`'gatsby' is not specified as a dependency`
)
}
try {
const cmdPath =
resolveCwd.silent(`gatsby/dist/commands/${command}`) ||
// Old location of commands
resolveCwd.silent(`gatsby/dist/utils/${command}`)
if (!cmdPath)
return report.panic(
`There was a problem loading the local ${command} command. Gatsby may not be installed in your site's "node_modules" directory. Perhaps you need to run "npm install"? You might need to delete your "package-lock.json" as well.`
)
report.verbose(`loading local command from: ${cmdPath}`)
const cmd = require(cmdPath)
if (cmd instanceof Function) {
return cmd
}
return report.panic(
`Handler for command "${command}" is not a function. Your Gatsby package might be corrupted, try reinstalling it and running the command again.`
)
} catch (err) {
cli.showHelp()
return report.panic(
`There was a problem loading the local ${command} command. Gatsby may not be installed. Perhaps you need to run "npm install"?`,
errView on GitHub (pinned to 8b06340921)
Solutions
- Run `npm install` (or `yarn`) in the project root to install gatsby into `node_modules`.
- If install still fails, delete the lockfile (`package-lock.json` / `yarn.lock`) and `node_modules`, then reinstall.
- Verify `node_modules/gatsby/dist/commands/<command>.js` exists after install.
- Ensure the gatsby version declared in `package.json` is resolvable from the registry.
Example fix
# before: gatsby declared but not installed gatsby develop # -> error # after rm -rf node_modules package-lock.json npm install gatsby develop
Defensive patterns
Strategy: validation
Validate before calling
// Verify gatsby is installed under node_modules before invoking
const fs = require('fs'); const path = require('path')
const cmdFile = path.join('node_modules', 'gatsby', 'dist', 'commands', `${command}.js`)
if (!fs.existsSync(cmdFile)) throw new Error('Run npm install first') Prevention
- Run `npm install`/`yarn` after every fresh clone.
- Commit a working lockfile and use the same package manager.
- Delete lockfile + node_modules and reinstall on persistent failures.
When it happens
Trigger: `package.json` declares gatsby but `node_modules/gatsby` is absent or incomplete (missing `dist/commands/<command>.js`). Typical after a clone without install, a failed/partial install, or a corrupted lockfile.
Common situations: Fresh clone where `npm install`/`yarn` was not run; switching package managers left a stale/incomplete `node_modules`; a lockfile conflict resolved incorrectly; a globally-installed gatsby being shadowed by a broken local one.
Related errors
- There was a problem loading the local ${command} command. Ga
- gatsby <${command}> can only be run for a gatsby site. Eithe
- Handler for command "${command}" is not a function. Your Gat
- Could not find "gatsby" in ${rootPath}. Perhaps it wasn't in
- Could not find a suitable version of gatsby-cli. Please repo
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/29c9eb17ce6a53e0.
Report an issue: GitHub.