{"record":{"id":"9d834c970e028d75","repo":"anomalyco/sst","slug":"could-not-find-handler-file-handler-for-funct","errorCode":null,"errorMessage":"Could not find handler file \"${handler}\" for function \"${name}\"","messagePattern":"Could not find handler file \"(.+?)\" for function \"(.+?)\"","errorType":"validation","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/function.ts","lineNumber":2178,"sourceCode":"          const hasUserInjections = injections.length > 0;\n\n          if (!hasUserInjections) return { handler };\n\n          const parsed = path.posix.parse(handler);\n          const handlerDir = parsed.dir;\n          const oldHandlerFileName = parsed.name;\n          const oldHandlerFunction = parsed.ext.replace(/^\\./, \"\");\n          const newHandlerFileName = \"server-index\";\n          const newHandlerFunction = \"handler\";\n\n          // Validate handler file exists\n          const newHandlerFileExt = [\".js\", \".mjs\", \".cjs\"].find((ext) =>\n            fs.existsSync(\n              path.join(bundle!, handlerDir, oldHandlerFileName + ext),\n            ),\n          );\n          if (!newHandlerFileExt) {\n            throw new VisibleError(\n              `Could not find handler file \"${handler}\" for function \"${name}\"`,\n            );\n          }\n\n          const split = injections.reduce(\n            (acc, item) => {\n              if (item.startsWith(\"outer:\")) {\n                acc.outer.push(item.substring(\"outer:\".length));\n                return acc;\n              }\n              acc.inner.push(item);\n              return acc;\n            },\n            { outer: [] as string[], inner: [] as string[] },\n          );\n\n          return {\n            handler: path.posix.join(","sourceCodeStart":2160,"sourceCodeEnd":2196,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/function.ts#L2160-L2196","documentation":"buildHandlerWrapper() injects wrapper code into the built bundle and must locate the compiled handler file (with .js, .mjs, or .cjs extension) inside the bundle. When no such file exists for the configured handler, it throws this VisibleError naming the function.","triggerScenarios":"The `handler` arg points to a file that doesn't exist (or has an unusual extension) at build time, e.g. handler: \"src/notfound.handler\" or handler referencing a file excluded from the bundle. Common when using wrappers/hooks with a misconfigured handler path.","commonSituations":"Renaming or deleting the source file without updating sst.config.ts; handler path relative to the wrong directory; building TypeScript files with custom extensions not among .js/.mjs/.cjs.","solutions":["Fix the handler path in sst.config.ts to point at the real file, e.g. handler: \"src/index.handler\"","Verify the file exists in the project relative to the config root","If using a custom extension, add a build option or rename the file to .ts producing .js output"],"exampleFix":"// before\nnew sst.aws.Function(\"Fn\", { handler: \"src/servce.handler\" });\n// after\nnew sst.aws.Function(\"Fn\", { handler: \"src/service.handler\" });","handlingStrategy":"validation","validationCode":"import fs from \"path\";\nimport path from \"path\";\nconst [file] = handler.split(\".\");\nif (!fs.existsSync(path.join(appRoot, `${file}.ts`)))\n  throw new Error(`Handler source missing: ${handler}`);","typeGuard":null,"tryCatchPattern":"try {\n  const fn = new sst.aws.Function(\"Fn\", { handler, wrapper });\n} catch (e) {\n  if ((e as Error).message.includes(\"Could not find handler file\")) {\n    console.error(`Check handler path for function: ${(e as Error).message}`);\n  }\n  throw e;\n}","preventionTips":["Update handler paths whenever you rename or move source files","Use the sst.aws.Function type-checked handler option to catch bad paths at typecheck","Keep handler files in a conventional layout (src/*.handler.ts) so paths are predictable"],"tags":["aws","lambda","handler","file-not-found"],"backgroundTag":"handler-file-not-found","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}