{"record":{"id":"b35305632ae9da3b","repo":"anomalyco/sst","slug":"could-not-find-a-target-file","errorCode":null,"errorMessage":"Could not find a ${target} file","messagePattern":"Could not find a (.+?) file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"platform/src/util/fs.ts","lineNumber":33,"sourceCode":"  async function loop(dir: string): Promise<string | undefined> {\n    const current = path.join(dir, target);\n    if (await existsAsync(current)) return dir;\n\n    const files = await fs.readdir(dir, { withFileTypes: true });\n    for (const file of files) {\n      if (file.name === \"node_modules\") continue;\n      if (file.name === \".sst\") continue;\n      if (file.isDirectory()) {\n        const full = path.join(dir, file.name);\n        const result = await loop(full);\n        if (result) return result;\n      }\n    }\n    return;\n  }\n\n  const value = await loop(dir);\n  if (!value) throw new Error(`Could not find a ${target} file`);\n  return value;\n}\n\nexport function isChild(parent: string, child: string) {\n  const relative = path.relative(parent, child);\n  return Boolean(\n    relative && !relative.startsWith(\"..\") && !path.isAbsolute(relative),\n  );\n}\n\nexport async function existsAsync(input: string) {\n  return fs\n    .access(input)\n    .then(() => true)\n    .catch(() => false);\n}\n","sourceCodeStart":15,"sourceCodeEnd":50,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/util/fs.ts#L15-L50","documentation":"findBelow searches a directory and (skipping node_modules and .sst) all its subdirectories for a given target file name (e.g. 'sst.config.ts' or 'package.json') and returns the containing directory. This error is thrown when the search completes and no file with that name exists anywhere below the starting directory.","triggerScenarios":"Running an sst command from a directory tree that does not contain the target file — e.g. invoking the CLI outside an SST app so no sst.config.ts exists below the working directory, or the file was deleted/renamed (e.g. 'sst.config.ts' vs 'Sst.config.ts' case mismatch).","commonSituations":"Running `sst deploy`/`sst dev` in the repo root when the config lives in a subdirectory and sst was invoked outside it; a missing or renamed sst.config.ts; working from a freshly cloned repo without the config checked in; .gitignore excluding the config file.","solutions":["cd into the directory containing the target file (or a subdirectory of it) before running the command.","Verify the file exists: ls the project for sst.config.ts and create it if missing (sst init can scaffold it).","Check the exact file name and casing matches what the CLI expects (case-sensitive on Linux).","If the config is gitignored, remove that ignore rule and commit the file so other checkouts have it."],"exampleFix":"// before\n$ cd ~/projects/app/frontend && sst deploy   # no sst.config.ts below frontend/\n// after\n$ cd ~/projects/app && sst deploy            # sst.config.ts lives here","handlingStrategy":"try-catch","validationCode":"import fs from \"fs/promises\";\nconst exists = await fs.access(path.join(process.cwd(), \"sst.config.ts\")).then(() => true, () => false);\nif (!exists) console.error(\"Run this command from an SST app directory containing sst.config.ts\");","typeGuard":"async function hasTarget(dir: string, target: string): Promise<boolean> {\n  try { await fs.access(path.join(dir, target)); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  const dir = await findBelow(process.cwd(), \"sst.config.ts\");\n} catch (e) {\n  if ((e as Error).message.startsWith(\"Could not find a\")) {\n    console.error(`No target found below cwd — run from your SST app root`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Always run sst commands from the project root where sst.config.ts lives.","Verify the config file exists and is committed (not gitignored) before invoking the CLI.","Watch for filename casing differences across OSes (sst.config.ts vs Sst.config.ts).","Script wrappers can pre-check for the file and print a friendly message before calling sst."],"tags":["filesystem","configuration","missing-file","cli"],"backgroundTag":"missing-config-file","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}