{"record":{"id":"44e4f8383cbd68b6","repo":"remix-run/react-router","slug":"package-json-pkgkey-are-invalid","errorCode":null,"errorMessage":"package.json ${pkgKey} are invalid","messagePattern":"package\\.json (.+?) are invalid","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-react-router/index.ts","lineNumber":695,"sourceCode":"    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\n  for (let pkgKey of [\"dependencies\", \"devDependencies\"] as const) {\n    let dependencies = packageJSON[pkgKey];\n    if (!dependencies) continue;\n\n    if (!isValidJsonObject(dependencies)) {\n      error(\n        \"Oh no!\",\n        \"The provided template must be a React Router project with a `package.json` \" +\n          `file, but its ${pkgKey} value is invalid.`,\n      );\n      throw new Error(`package.json ${pkgKey} are invalid`);\n    }\n\n    for (let dependency in dependencies) {\n      let version = dependencies[dependency];\n      if (\n        (dependency.startsWith(\"@react-router/\") ||\n          dependency === \"react-router\") &&\n        version === \"*\"\n      ) {\n        dependencies[dependency] = semver.prerelease(ctx.reactRouterVersion)\n          ? // Templates created from prereleases should pin to a specific version\n            ctx.reactRouterVersion\n          : \"^\" + ctx.reactRouterVersion;\n      }\n    }\n  }\n\n  packageJSON.name = ctx.projectName;","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/remix-run/react-router/blob/1fd704a7dabcbe3ae09d7387b460e6acaba30ec1/packages/create-react-router/index.ts#L677-L713","documentation":"Thrown in updatePackageJSON() while iterating over ['dependencies','devDependencies']: the package.json parsed fine, but one of these fields is present and is not a valid JSON object (isValidJsonObject fails — it's an array, string, number, null, or otherwise non-object). React Router needs to rewrite react-router/@react-router/* versions in these maps, so they must be plain objects.","triggerScenarios":"A template whose package.json has \"dependencies\": \"./libs\" (string), \"dependencies\": [\"react\"] (array), or \"devDependencies\": null. Any non-object JSON value for either field triggers the throw.","commonSituations":"Hand-edited package.json with a typo; a template generated by tooling that wrote dependencies as a list; a JSON merge that produced a non-object value; copy-pasting from a docs example that used a non-standard format.","solutions":["Open the template's package.json and ensure dependencies and devDependencies are both plain objects like { \"react\": \"^18.0.0\" }.","Remove the field entirely if it should be empty (an absent field is skipped via the `if (!dependencies) continue` guard).","Validate the JSON with npm/your editor and fix the malformed value.","After fixing, re-run create-react-router."],"exampleFix":"// before (template package.json)\n{\n  \"name\": \"bad-template\",\n  \"dependencies\": [\"react\", \"react-dom\"]\n}\n// after\n{\n  \"name\": \"bad-template\",\n  \"dependencies\": { \"react\": \"^18.0.0\", \"react-dom\": \"^18.0.0\" }\n}","handlingStrategy":"validation","validationCode":"function isValidDepsMap(v: unknown): boolean {\n  return v == null || (typeof v === 'object' && !Array.isArray(v));\n}\n// Validate the template's package.json shape before scaffolding\nconst pkg = JSON.parse(fs.readFileSync(path.join(templateDir, 'package.json'), 'utf-8'));\nif (!isValidDepsMap(pkg.dependencies) || !isValidDepsMap(pkg.devDependencies)) {\n  throw new Error('dependencies/devDependencies must be objects or absent');\n}","typeGuard":"function isValidJsonObject(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}","tryCatchPattern":null,"preventionTips":["Lint template package.json files with a JSON schema validator before publishing.","Keep dependencies/devDependencies as plain objects or omit them when empty.","Run `npm install` on the template locally to catch malformed dependency maps early.","Avoid hand-editing package.json arrays where maps are expected."],"tags":["cli","package-json","validation","create-react-router"],"backgroundTag":null,"analyzedSha":"1fd704a7dabcbe3ae09d7387b460e6acaba30ec1","analyzedAt":"2026-08-12T13:54:57.804Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}