{"record":{"id":"db37ed80fb82d5fc","repo":"facebook/docusaurus","slug":"failed-to-update-package-json","errorCode":null,"errorMessage":"Failed to update package.json.","messagePattern":"Failed to update package\\.json\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-docusaurus/src/index.ts","lineNumber":532,"sourceCode":"    try {\n      await fs.cp(source.path, dest, {recursive: true});\n    } catch (err) {\n      throw new Error(\n        logger.interpolate`Copying local template path=${source.path} failed!`,\n        {cause: err},\n      );\n    }\n  }\n\n  // Update package.json info.\n  try {\n    await updatePkg(path.join(dest, 'package.json'), {\n      name: siteNameToPackageName(siteName),\n      version: '0.0.0',\n      private: true,\n    });\n  } catch (err) {\n    throw new Error('Failed to update package.json.', {cause: err});\n  }\n\n  // We need to rename the gitignore file to .gitignore\n  if (\n    !(await pathExists(path.join(dest, '.gitignore'))) &&\n    (await pathExists(path.join(dest, 'gitignore')))\n  ) {\n    await fs.rename(\n      path.join(dest, 'gitignore'),\n      path.join(dest, '.gitignore'),\n    );\n  }\n  if (await pathExists(path.join(dest, 'gitignore'))) {\n    await fs.rm(path.join(dest, 'gitignore'));\n  }\n\n  // Display the most elegant way to cd.\n  const cdpath = path.relative('.', dest);","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/create-docusaurus/src/index.ts#L514-L550","documentation":"Thrown when updatePkg() fails to read or write the package.json that create-docusaurus expects to find (and patch with name/version/private) in the freshly copied destination. updatePkg parses, merges, and re-serializes JSON, so any parse error or write failure bubbles up here with the original error as `cause`.","triggerScenarios":"A custom or local template whose package.json is malformed JSON; a git-cloned template that has no package.json at the repo root; a read-only destination that blocks the write-back; an EISDIR/ENOENT because the path is a directory or missing.","commonSituations":"Using a community git template whose package.json has trailing commas or comments; a template that stores package.json in a subfolder instead of the root; running on a read-only mount; a previous copy step partially failed leaving a corrupt package.json.","solutions":["Open <dest>/package.json in a JSON validator and fix syntax errors, then re-run init in a clean directory.","Confirm the template has package.json at its root (not in a subdirectory).","Check err.cause.code: ENOENT means the template lacks package.json, EACCES/EROFS means a permissions issue.","Re-run create-docusaurus into a fresh destination after fixing the template."],"exampleFix":"// before (template package.json with a trailing comma)\n{\n  \"name\": \"x\",\n  \"version\": \"1.0.0\",\n}\n// after\n{\n  \"name\": \"x\",\n  \"version\": \"1.0.0\"\n}","handlingStrategy":"validation","validationCode":"import fs from 'node:fs/promises';\nasync function assertValidPackageJson(filePath: string) {\n  const raw = await fs.readFile(filePath, 'utf8');\n  try { JSON.parse(raw); } catch {\n    throw new Error(`package.json at ${filePath} is not valid JSON`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await init(...);\n} catch (err) {\n  if (/Failed to update package\\.json/.test((err as Error).message)) {\n    // open <dest>/package.json, validate JSON, fix, retry in a clean dest\n  }\n  throw err;\n}","preventionTips":["Validate template package.json with a JSON linter before publishing/using it.","Keep package.json at the template root.","Inspect err.cause.code (ENOENT / EACCES) to choose the right fix."],"tags":["create-docusaurus","package-json","filesystem","wrapped-error"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}