{"record":{"id":"1fe17ad2d2e32f6e","repo":"gatsbyjs/gatsby","slug":"error-when-executing-function-functionobj-origi","errorCode":null,"errorMessage":"Error when executing function \"${functionObj.originalAbsoluteFilePath}\":<br /><br />${e.message}","messagePattern":"Error when executing function \"(.+?)\":<br /><br />(.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"packages/gatsby/src/internal-plugins/functions/middleware.ts","lineNumber":141,"sourceCode":"      const pathToFunction = functionObj.absoluteCompiledFilePath\n      let fnToExecute\n      try {\n        delete require.cache[require.resolve(pathToFunction)]\n        const fn = require(pathToFunction)\n        userConfig = fn?.config\n\n        fnToExecute = (fn && fn.default) || fn\n      } catch (e) {\n        if (e?.message?.includes(`fnToExecute is not a function`)) {\n          e.message = `${functionObj.originalAbsoluteFilePath} does not export a function.`\n        }\n\n        fnToExecute = undefined\n        reporter.error(e)\n        if (!res.headersSent) {\n          if (showDebugMessageInResponse) {\n            res\n              .status(500)\n              .send(\n                `Error when executing function \"${functionObj.originalAbsoluteFilePath}\":<br /><br />${e.message}`\n              )\n          } else {\n            res.sendStatus(500)\n          }\n        }\n        return\n      }\n\n      if (fnToExecute) {\n        const { config, warnings } = createConfig(userConfig)\n\n        printConfigWarnings(warnings, functionObj)\n\n        req.context = {\n          functionObj,\n          fnToExecute,","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/e85d62f1779e353eaac1753211629a26d123e26c/packages/gatsby/src/internal-plugins/functions/middleware.ts#L123-L159","documentation":"createSetContextFunctionMiddleware requires each compiled Gatsby function module; failures here mean the file could not be loaded (syntax error, missing dependency, or no default function export — that case gets a tailored message). The error is reported and an HTML error response is prepared for the request.","triggerScenarios":"Thrown at packages/gatsby/src/internal-plugins/functions/middleware.ts:141 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the function file exports a default function","Fix syntax/import errors in the function file","Check the function compiles (see reporter output) before redeploying"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e85d62f1779e353eaac1753211629a26d123e26c","analyzedAt":"2026-08-26T17:50:09.662Z","contentChangedAt":"2026-08-26T17:50:09.662Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}