{"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/6beaca39526d5716c3c112ebb0782765baa5a9ce/packages/create-react-router/index.ts#L648-L684","documentation":"After copying the template into the project directory, updatePackageJSON() requires a package.json there because it rewrites react-router dependency versions and the project name. A template without a package.json is not a valid React Router project, so the CLI aborts with the resolved project path in the message.","triggerScenarios":"--template pointing at a repo subdirectory that is not an app (a docs/ folder, an example with only a README); a custom template directory missing package.json; a tarball whose project files are nested one level below the root that strip-1 extraction removes.","commonSituations":"Pointing at a monorepo root or wrong folder; hand-built templates without a manifest; tarballs packed with an extra top-level directory.","solutions":["Point --template at the directory that actually contains package.json","Add a package.json (with react-router / @react-router/* dependencies) to your template root","Re-pack the tarball so package.json sits at the archive root's top level"],"exampleFix":"# before: repo root has no package.json at that level\nnpx create-react-router my-app --template https://github.com/acme/mono/tree/main/packages\n\n# after: point at the actual app package\nnpx create-react-router my-app --template https://github.com/acme/mono/tree/main/packages/app","handlingStrategy":"validation","validationCode":"import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\n\nfunction templateHasPackageJson(templateDir: string): boolean {\n  return existsSync(path.join(templateDir, \"package.json\"));\n}\n\nif (!templateHasPackageJson(templateDir)) {\n  throw new Error(\"Template must be a React Router project containing package.json\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await createReactRouter(args);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (/package\\.json does not exist in/.test(msg)) {\n    console.error(\"Template lacks package.json — point --template at the app package directory.\");\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Author custom templates from a working create-react-router project so package.json is guaranteed","When packing tarballs, keep package.json at the root level (top dir is stripped on extract)","Verify template structure in CI with a check job before publishing"],"tags":["cli","template","package-json"],"backgroundTag":"missing-package-json","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"}