{"record":{"id":"43fced40773cdd45","repo":"remix-run/react-router","slug":"could-not-find-package-json-in-rootdirectory-or","errorCode":null,"errorMessage":"Could not find package.json in ${rootDirectory} or any of its parent directories. Please add a package.json, or provide a custom entry.server.tsx/jsx file in your app directory.","messagePattern":"Could not find package\\.json in (.+?) or any of its parent directories\\. Please add a package\\.json, or provide a custom entry\\.server\\.tsx/jsx file in your app directory\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-router-dev/config/config.ts","lineNumber":1047,"sourceCode":"  );\n\n  let userEntryClientFile = findEntry(appDirectory, \"entry.client\");\n  let userEntryServerFile = findEntry(appDirectory, \"entry.server\");\n\n  let entryServerFile: string;\n  let entryClientFile = userEntryClientFile || \"entry.client.tsx\";\n\n  if (userEntryServerFile) {\n    entryServerFile = userEntryServerFile;\n  } else {\n    let packageJsonPath = findEntry(rootDirectory, \"package\", {\n      extensions: [\".json\"],\n      absolute: true,\n      walkParents: true,\n    });\n\n    if (!packageJsonPath) {\n      throw new Error(\n        `Could not find package.json in ${rootDirectory} or any of its parent directories. Please add a package.json, or provide a custom entry.server.tsx/jsx file in your app directory.`,\n      );\n    }\n\n    let packageJsonDirectory = Path.dirname(packageJsonPath);\n    let pkgJson = await readPackageJSON(packageJsonDirectory);\n    let deps = pkgJson.dependencies ?? {};\n\n    if (!deps[\"isbot\"]) {\n      console.log(\n        \"adding `isbot@5` to your package.json, you should commit this change\",\n      );\n\n      await updatePackage(packageJsonPath, (pkg) => {\n        pkg.dependencies ??= {};\n        pkg.dependencies.isbot = \"^5\";\n        sortPackage(pkg);\n      });","sourceCodeStart":1029,"sourceCodeEnd":1065,"githubUrl":"https://github.com/remix-run/react-router/blob/1fd704a7dabcbe3ae09d7387b460e6acaba30ec1/packages/react-router-dev/config/config.ts#L1029-L1065","documentation":"Thrown during entry-server resolution when no custom entry.server file exists in the app directory AND findEntry cannot locate a package.json in rootDirectory or any parent (walkParents: true). React Router needs package.json both to choose the default entry.server (node vs web) and to ensure the isbot dependency is present; without it, defaulting cannot proceed safely. The message suggests either adding a package.json or providing a custom app/entry.server.tsx/jsx.","triggerScenarios":"Running react-router build/dev in a directory that has no package.json anywhere up the tree (e.g. scaffolding files by hand, or pointing the tool at a bare subfolder); the project root was misconfigured; package.json was deleted or never created; running inside a sandbox that excludes the parent package.json.","commonSituations":"Standalone experiment folders without package.json; an incorrectly set rootDirectory/appDirectory; monorepo where the tool was invoked from a directory above the package; filesystem permission issue hiding package.json.","solutions":["Ensure a package.json exists at or above the project root (npm init -y in the project directory).","Run react-router build from the directory that contains package.json.","Add a custom app/entry.server.tsx (or .jsx) so the default-resolution path that needs package.json is skipped.","If in a monorepo, confirm the tool resolves the workspace root that contains package.json; check rootDirectory in react-router.config.ts.","Reinstall dependencies (npm install) so isbot and other deps are present after adding package.json."],"exampleFix":"// before -- project dir has no package.json and no custom entry server\nreact-router build\n// after -- add package.json (or add app/entry.server.tsx)\nnpm init -y && npm install && react-router build\n// alternative: create app/entry.server.tsx to bypass default resolution","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\nfunction hasPackageJsonUpTree(start: string): boolean {\n  let dir = start;\n  while (true) {\n    if (fs.existsSync(path.join(dir, 'package.json'))) return true;\n    const parent = path.dirname(dir);\n    if (parent === dir) return false;\n    dir = parent;\n  }\n}\n// if (!hasPackageJsonUpTree(rootDirectory)) -> create package.json or add app/entry.server.tsx","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always scaffold with a package.json at the project root (npm init -y).","Run react-router build from the directory containing package.json.","Provide a custom app/entry.server.tsx if you intentionally have no package.json.","In monorepos, double-check rootDirectory/appDirectory in react-router.config.ts."],"tags":["config","entry-server","package-json","react-router-dev","framework-mode"],"backgroundTag":null,"analyzedSha":"1fd704a7dabcbe3ae09d7387b460e6acaba30ec1","analyzedAt":"2026-08-12T13:54:57.804Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}