{"record":{"id":"fbd8228a7555a53d","repo":"remix-run/react-router","slug":"could-not-find-the-routes-directory-routesdir","errorCode":null,"errorMessage":"Could not find the routes directory: ${routesDir}. Did you forget to create it?","messagePattern":"Could not find the routes directory: (.+?)\\. Did you forget to create it\\?","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-router-fs-routes/flatRoutes.ts","lineNumber":93,"sourceCode":"  appDirectory: string,\n  ignoredFilePatterns: string[] = [],\n  prefix = \"routes\",\n) {\n  let ignoredFileRegex = Array.from(new Set([\"**/.*\", ...ignoredFilePatterns]))\n    .map((re) => makeRe(re))\n    .filter((re: any): re is RegExp => !!re);\n  let routesDir = path.join(appDirectory, prefix);\n\n  let rootRoute = findFile(appDirectory, \"root\", routeModuleExts);\n\n  if (!rootRoute) {\n    throw new Error(\n      `Could not find a root route module in the app directory: ${appDirectory}`,\n    );\n  }\n\n  if (!fs.existsSync(routesDir)) {\n    throw new Error(\n      `Could not find the routes directory: ${routesDir}. Did you forget to create it?`,\n    );\n  }\n\n  // Only read the routes directory\n  let entries = fs.readdirSync(routesDir, {\n    withFileTypes: true,\n    encoding: \"utf-8\",\n  });\n\n  let routes: string[] = [];\n  for (let entry of entries) {\n    let filepath = normalizeSlashes(path.join(routesDir, entry.name));\n\n    let route: string | null = null;\n    // If it's a directory, don't recurse into it, instead just look for a route module\n    if (entry.isDirectory()) {\n      route = findRouteModuleForFolder(","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/remix-run/react-router/blob/6beaca39526d5716c3c112ebb0782765baa5a9ce/packages/react-router-fs-routes/flatRoutes.ts#L75-L111","documentation":"After locating the root module, flatRoutes() verifies that the routes directory exists — appDirectory joined with the prefix argument (default 'routes'), i.e. app/routes by default. Even an empty routes directory is fine, but a missing one throws with a 'Did you forget to create it?' hint, because the subsequent readdirSync would otherwise crash with a raw ENOENT.","triggerScenarios":"Calling flatRoutes() (or flatRoutes({ prefix }) with a custom prefix) when app/routes — or appDirectory + prefix — does not exist on disk.","commonSituations":"Fresh repo where the empty routes folder was never committed (git doesn't track empty directories); renaming the routes dir to 'pages' without passing a matching prefix; custom routesDirectory/prefix configs drifting from the actual layout.","solutions":["Create the directory: mkdir -p app/routes (an empty directory with no files is valid)","If your routes live elsewhere, pass the matching prefix so appDirectory + prefix resolves to the real folder","Commit a placeholder (e.g. app/routes/.gitkeep) so fresh clones keep the directory"],"exampleFix":"# before\napp/\n  root.tsx          # no routes/ directory\n\n# after\napp/\n  root.tsx\n  routes/\n    _index.tsx","handlingStrategy":"validation","validationCode":"import fs from \"node:fs\";\nimport path from \"node:path\";\nconst routesDir = path.join(appDirectory, prefix ?? \"routes\");\nif (!fs.existsSync(routesDir)) {\n  throw new Error(`Create ${routesDir} (even empty) before calling flatRoutes()`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Commit a .gitkeep inside app/routes so fresh clones keep the directory","Keep the flatRoutes prefix in sync with the actual folder name","Scaffold new apps with both root.* and routes/ present"],"tags":["file-routing","fs-routes","directory","enoent","config"],"backgroundTag":"missing-directory","analyzedSha":"6beaca39526d5716c3c112ebb0782765baa5a9ce","analyzedAt":"2026-08-18T18:04:14.938Z","contentChangedAt":"2026-08-18T18:04:14.938Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}