{"record":{"id":"2c1ab4fdc92fc355","repo":"gatsbyjs/gatsby","slug":"handler-for-command-command-is-not-a-function","errorCode":null,"errorMessage":"Handler for command \"${command}\" is not a function. Your Gatsby package might be corrupted, try reinstalling it and running the command again.","messagePattern":"Handler for command \"(.+?)\" is not a function\\. Your Gatsby package might be corrupted, try reinstalling it and running the command again\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-cli/src/create-cli.ts","lineNumber":90,"sourceCode":"\n    try {\n      const cmdPath =\n        resolveCwd.silent(`gatsby/dist/commands/${command}`) ||\n        // Old location of commands\n        resolveCwd.silent(`gatsby/dist/utils/${command}`)\n      if (!cmdPath)\n        return report.panic(\n          `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.`\n        )\n\n      report.verbose(`loading local command from: ${cmdPath}`)\n\n      const cmd = require(cmdPath)\n      if (cmd instanceof Function) {\n        return cmd\n      }\n\n      return report.panic(\n        `Handler for command \"${command}\" is not a function. Your Gatsby package might be corrupted, try reinstalling it and running the command again.`\n      )\n    } catch (err) {\n      cli.showHelp()\n      return report.panic(\n        `There was a problem loading the local ${command} command. Gatsby may not be installed. Perhaps you need to run \"npm install\"?`,\n        err\n      )\n    }\n  }\n\n  function getCommandHandler(\n    command: string,\n    handler?: (\n      args: yargs.Arguments,\n      cmd: (args: yargs.Arguments) => void\n    ) => void,\n    nodeEnv?: string | undefined","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-cli/src/create-cli.ts#L72-L108","documentation":"Thrown after `require(cmdPath)` succeeds but the resolved export is not a function. Each gatsby command module must default-export (or module.exports) a function; if the loaded file exports an object, undefined, or a non-function, the CLI considers the gatsby installation corrupted.","triggerScenarios":"The command file at `node_modules/gatsby/dist/commands/<command>.js` was found and loaded, but its export is not callable. Caused by a truncated/modified gatsby package, a conflicting local file shadowing the command, or an incompatible Gatsby major version whose command contract changed.","commonSituations":"A botched `npm install`/`yarn` left a partial gatsby package; a manual edit to files under `node_modules/gatsby`; a version mismatch between gatsby CLI and the local gatsby package; a transpiler/bundler that rewrote the command module's exports.","solutions":["Reinstall the gatsby package cleanly: `rm -rf node_modules/gatsby && npm install gatsby`.","If the issue persists, wipe and reinstall everything: `rm -rf node_modules package-lock.json && npm install`.","Confirm the gatsby CLI version is compatible with the locally installed gatsby package version.","Check no local file at `./commands/<command>.js` or a similarly named module is shadowing the real command."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"const cmd = require(cmdPath)\nif (typeof cmd !== 'function') throw new Error('Corrupted gatsby install; reinstall')","typeGuard":"const isCommandHandler = (v: unknown): v is (...args: any[]) => void => typeof v === 'function'","tryCatchPattern":null,"preventionTips":["Reinstall gatsby cleanly if its dist files were touched.","Avoid manual edits under `node_modules/gatsby`.","Keep gatsby CLI and local gatsby package versions compatible."],"tags":["cli","command-loading","corrupted-install","node-modules"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}