{"record":{"id":"ff07dfaccd7007d0","repo":"remix-run/react-router","slug":"package-json-does-not-exist-in-ctx-cwd","errorCode":null,"errorMessage":"package.json does not exist in ${ctx.cwd}","messagePattern":"package\\.json does not exist in (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-react-router/index.ts","lineNumber":666,"sourceCode":"              ? `${command} exited with signal ${signal}`\n              : `${command} exited with code ${code}`,\n          ),\n        );\n      }\n    });\n  });\n}\n\nasync function updatePackageJSON(ctx: Context) {\n  let packageJSONPath = path.join(ctx.cwd, \"package.json\");\n  if (!existsSync(packageJSONPath)) {\n    let relativePath = path.relative(process.cwd(), ctx.cwd);\n    error(\n      \"Oh no!\",\n      \"The provided template must be a React Router project with a `package.json` \" +\n        `file, but that file does not exist in ${color.bold(relativePath)}.`,\n    );\n    throw new Error(`package.json does not exist in ${ctx.cwd}`);\n  }\n\n  let contents = await readFile(packageJSONPath, \"utf-8\");\n  let packageJSON: any;\n  try {\n    packageJSON = JSON.parse(contents);\n    if (!isValidJsonObject(packageJSON)) {\n      throw Error();\n    }\n  } catch (err) {\n    error(\n      \"Oh no!\",\n      \"The provided template must be a React Router project with a `package.json` \" +\n        `file, but that file is invalid.`,\n    );\n    throw err;\n  }\n","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/remix-run/react-router/blob/1fd704a7dabcbe3ae09d7387b460e6acaba30ec1/packages/create-react-router/index.ts#L648-L684","documentation":"Thrown in updatePackageJSON() when, after copying the template into ctx.cwd, no package.json exists at <cwd>/package.json. The CLI requires every template to be a React Router project, which means it must ship a package.json. Its absence means the template itself is not a valid project, or the copy step was filtered down to nothing.","triggerScenarios":"Using --template that points at a docs directory, a single example file, or a non-project folder that has no package.json; the template tarball's top-level was stripped incorrectly (strip:1 removed the only layer that contained package.json); a GitHub subdirectory that is documentation-only.","commonSituations":"Pointing at a monorepo subpackage that has no package.json (e.g. /docs or /examples with nested projects); a community template that isn't actually a React Router project; copy filter removed everything because the archive layout differed.","solutions":["Open the template source and confirm a package.json exists at its root (or chosen subdirectory).","Switch to the official default template by omitting --template.","If the template lives in a subdirectory, point --template at that exact subdirectory (owner/repo/subdir or /tree/:branch/:dir).","If the template is yours, add a minimal package.json with name/version/scripts before publishing."],"exampleFix":"// before -- subdir has no package.json\ncreate-react-router my-app --template https://github.com/acme/mono/tree/main/docs\n// after -- point at the actual project subdir\ncreate-react-router my-app --template https://github.com/acme/mono/tree/main/apps/web","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\nfunction templateHasPackageJson(templateRoot: string): boolean {\n  return fs.existsSync(path.join(templateRoot, 'package.json'));\n}\n// Before relying on a custom template, assert templateHasPackageJson(dir).","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use templates that are actual React Router projects (root package.json present).","When pointing at a subdirectory, confirm package.json lives in that subdirectory.","Prefer the official default template when unsure.","For custom templates, run npm init and add the React Router scripts/dependencies first."],"tags":["cli","template","package-json","create-react-router"],"backgroundTag":null,"analyzedSha":"1fd704a7dabcbe3ae09d7387b460e6acaba30ec1","analyzedAt":"2026-08-12T13:54:57.804Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}