{"record":{"id":"a4301aabc7b7e475","repo":"vercel/turborepo","slug":"unable-to-read-package-json","errorCode":null,"errorMessage":"Unable to read package.json","messagePattern":"Unable to read package\\.json","errorType":"exception","errorClass":"TransformError","httpStatus":null,"severity":"error","filePath":"packages/create-turbo/src/transforms/official-starter.ts","lineNumber":54,"sourceCode":"\n  let metaJson: MetaJson | undefined;\n\n  // 1. remove meta file (used for generating the examples page on turborepo.dev)\n  try {\n    metaJson = fs.readJsonSync(rootMetaJsonPath) as MetaJson;\n    fs.rmSync(rootMetaJsonPath, { force: true });\n  } catch (_err) {\n    // do nothing\n  }\n\n  if (hasPackageJson) {\n    let packageJsonContent: PackageJson | undefined;\n    try {\n      packageJsonContent = fs.readJsonSync(rootPackageJsonPath) as\n        | PackageJson\n        | undefined;\n    } catch {\n      throw new TransformError(\"Unable to read package.json\", {\n        transform: meta.name,\n        fatal: false\n      });\n    }\n\n    // if using the basic example, set the name to the project name (legacy behavior)\n    if (packageJsonContent) {\n      if (defaultExample) {\n        packageJsonContent.name = prompts.projectName;\n      }\n\n      if (packageJsonContent.devDependencies?.turbo) {\n        // if the user specified a turbo version, use that\n        if (opts.turboVersion) {\n          packageJsonContent.devDependencies.turbo = opts.turboVersion;\n          // use the same version as the create-turbo invocation\n        } else {\n          // eslint-disable-next-line @typescript-eslint/no-var-requires -- Have to go get package.json","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/vercel/turborepo/blob/f9245100cf0d31d96628804ead485f6bf226e55a/packages/create-turbo/src/transforms/official-starter.ts#L36-L72","documentation":"The official-starter transform in create-turbo reads the root package.json of the downloaded starter with fs.readJsonSync. It throws this TransformError when the file cannot be read or parsed as JSON. This means the starter's package.json is missing at read time, unreadable, or contains malformed JSON.","triggerScenarios":"create-turbo downloads an example whose root package.json is not valid JSON, or the file cannot be opened due to permissions or a corrupted download. fs.readJsonSync throws inside the try block and the catch converts it to this TransformError.","commonSituations":"Using --example with a custom repository that has a syntax error in package.json, such as a trailing comma or a smart quote. A proxy or antivirus altering the extracted file. An example repository whose layout changed so the copied root lacks a valid package.json.","solutions":["If you used a custom --example, open its package.json in a JSON validator and fix any syntax errors","Re-run create-turbo with the default example to confirm the tool works, then retry your custom example","Check that the extracted starter directory is readable and was not modified by antivirus or proxy software","If an official example fails, report the broken example to the Turborepo repository"],"exampleFix":"// before: invalid JSON in the example's package.json\n{ \"name\": \"my-app\", \"version\": \"1.0.0\", }\n// after: valid JSON\n{\n  \"name\": \"my-app\",\n  \"version\": \"1.0.0\"\n}","handlingStrategy":"validation","validationCode":"import fs from \"node:fs\";\n\n// validate a custom example's package.json before passing it to create-turbo\nfunction hasValidRootPackageJson(exampleDir: string): boolean {\n  try {\n    const raw = fs.readFileSync(`${exampleDir}/package.json`, \"utf8\");\n    const parsed = JSON.parse(raw);\n    return typeof parsed === \"object\" && parsed !== null;\n  } catch {\n    return false;\n  }\n}","typeGuard":"function isValidJsonFile(raw: string): boolean {\n  try {\n    JSON.parse(raw);\n    return true;\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  const pkg = fs.readJsonSync(pkgPath);\n} catch (err) {\n  const reason = (err as NodeJS.ErrnoException).code === \"ENOENT\"\n    ? \"package.json is missing\"\n    : \"package.json is not valid JSON\";\n  throw new Error(`${reason}: ${pkgPath}`);\n}","preventionTips":["Run JSON validation in CI for every repository used with --example","Use a JSON-aware editor or prettier so syntax errors surface on save","Keep example repositories on stable layouts that include a root package.json"],"tags":["create-turbo","json","package-json","parsing","starter"],"backgroundTag":"invalid-json-parse","analyzedSha":"f9245100cf0d31d96628804ead485f6bf226e55a","analyzedAt":"2026-08-17T10:46:15.696Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}