{"record":{"id":"248968f1778b9a19","repo":"vercel/turborepo","slug":"unable-to-write-package-json","errorCode":null,"errorMessage":"Unable to write package.json","messagePattern":"Unable to write package\\.json","errorType":"exception","errorClass":"TransformError","httpStatus":null,"severity":"error","filePath":"packages/create-turbo/src/transforms/official-starter.ts","lineNumber":84,"sourceCode":"      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\n          const version = (require(\"../../package.json\") as { version: string })\n            .version;\n          packageJsonContent.devDependencies.turbo = `^${version}`;\n        }\n      }\n\n      try {\n        fs.writeJsonSync(rootPackageJsonPath, packageJsonContent, {\n          spaces: 2\n        });\n      } catch (err) {\n        throw new TransformError(\"Unable to write package.json\", {\n          transform: meta.name,\n          fatal: false\n        });\n      }\n    }\n  }\n\n  return { result: \"success\", metaJson, ...meta };\n}\n","sourceCodeStart":66,"sourceCodeEnd":94,"githubUrl":"https://github.com/vercel/turborepo/blob/9f94a7d215b3881942527dd526afa3fc650869d5/packages/create-turbo/src/transforms/official-starter.ts#L66-L94","documentation":"Thrown by create-turbo's official-starter transform when it cannot write the modified starter package.json back to disk. The transform mutates the starter's package.json (sets the project name for the basic example, pins the bundled turbo version) and persists it with fs.writeJsonSync; any failure of that write raises this non-fatal TransformError.","triggerScenarios":"fs.writeJsonSync(rootPackageJsonPath, packageJsonContent, { spaces: 2 }) throwing: EACCES/EROFS on the project root, ENOSPC, or EPERM because the file is locked by antivirus, an editor, or a sync client (typical on Windows).","commonSituations":"Scaffolding into an unwritable or read-only directory; OneDrive/Dropbox locking package.json as it syncs; endpoint protection scanning files the moment they are written; CI workspace mounted read-only.","solutions":["Ensure the target directory is writable (`chmod u+w <dir>` / run under $HOME) and re-run create-turbo","Close editors and pause cloud-sync/antivirus for the scaffold directory, then retry","Check free disk space (`df -h .`) and retry","If the scaffold otherwise completed, fix it manually: open the created package.json and set `name` and `devDependencies.turbo` yourself"],"exampleFix":"# before\nnpx create-turbo@latest my-app   # fails while OneDrive locks package.json\n# after\n# pause sync (or scaffold outside the synced folder), then:\nnpx create-turbo@latest my-app","handlingStrategy":"try-catch","validationCode":"import fs from 'node:fs';\n\nfunction canWriteFile(p: string): boolean {\n  try {\n    fs.accessSync(fs.dirname ?? fsConstants(p), fs.constants.W_OK);\n    return true;\n  } catch {\n    return false;\n  }\n}\n// simpler: fs.accessSync(projectRoot, fs.constants.W_OK) before invoking create-turbo","typeGuard":null,"tryCatchPattern":"try {\n  await createApp({ root });\n} catch (err) {\n  if (err instanceof TransformError && err.fatal === false && /package\\.json/.test(err.message)) {\n    // recover manually: apply the two mutations yourself (project name + turbo version)\n    const pkg = JSON.parse(fs.readFileSync(`${root}/package.json`, 'utf8'));\n    pkg.devDependencies ??= {};\n    pkg.devDependencies.turbo = `^${installedTurboVersion}`;\n    fs.writeFileSync(`${root}/package.json`, JSON.stringify(pkg, null, 2));\n  } else throw err;\n}","preventionTips":["Scaffold outside cloud-synced folders, or pause sync during scaffolding","Add antivirus exclusions for your projects directory on Windows","Confirm the target directory is writable before invoking create-turbo"],"tags":["create-turbo","filesystem","permissions","package-json","scaffolding"],"backgroundTag":"file-write-permission-denied","analyzedSha":"9f94a7d215b3881942527dd526afa3fc650869d5","analyzedAt":"2026-08-16T19:47:29.531Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}