{"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/9f94a7d215b3881942527dd526afa3fc650869d5/packages/create-turbo/src/transforms/official-starter.ts#L36-L72","documentation":"Thrown by create-turbo's official-starter transform after it downloads and extracts a starter example: it reads the extracted root package.json with fs.readJsonSync to adjust the project name and turbo version. If that file is missing, unreadable, or not valid JSON, this non-fatal TransformError is thrown.","triggerScenarios":"fs.readJsonSync(rootPackageJsonPath) throwing inside the transform: the starter extraction was incomplete (interrupted download/disk-full), a custom --example path has no root package.json, a permissions error, or the file contains malformed/truncated JSON.","commonSituations":"Flaky network cutting off example download mid-extract; passing --example a local directory or GitHub repo whose package.json sits in a subfolder; corporate proxies mangling tarballs; truncated files after a full disk.","solutions":["Delete the partial output directory and simply re-run create-turbo (transient download/extraction failures are the most common cause)","If using --example with a custom path, verify that path directly contains a valid package.json (test with `node -e \"JSON.parse(require('fs').readFileSync('<path>/package.json','utf8'))\"`)","Check disk space and directory permissions, then retry","Fall back to a known-good official example name (e.g. `--example basic`) to rule out the custom source"],"exampleFix":"# before\nnpx create-turbo@latest --example ./my-broken-example my-app\n# after\nnpx create-turbo@latest --example basic my-app","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\n\nfunction isValidExampleDir(dir: string): boolean {\n  const pkg = `${dir}/package.json`;\n  if (!fs.existsSync(pkg)) return false;\n  try {\n    JSON.parse(fs.readFileSync(pkg, 'utf8'));\n    return true;\n  } catch {\n    return false;\n  }\n}\n// run before: createTurbo({ example: myDir }) requires isValidExampleDir(myDir)","typeGuard":null,"tryCatchPattern":"try {\n  await createApp({ example });\n} catch (err) {\n  if (err instanceof TransformError && err.transform === meta.name) {\n    // message 'Unable to read package.json': safest recovery is cleanup + one retry\n    await fs.rm(targetDir, { recursive: true, force: true });\n    return createApp({ example }); // one bounded retry, then surface\n  }\n  throw err;\n}","preventionTips":["Validate custom --example directories contain a parseable root package.json before scaffolding","Pin the create-turbo version in CI (`create-turbo@x.y.z`) to avoid surprise starter-layout changes","Treat a first failure on flaky networks as transient: clean the partial output and retry once before debugging"],"tags":["create-turbo","json","filesystem","scaffolding","package-json"],"backgroundTag":"json-parse-error","analyzedSha":"9f94a7d215b3881942527dd526afa3fc650869d5","analyzedAt":"2026-08-16T19:47:29.531Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}