{"record":{"id":"40f83d757e29ab42","repo":"vercel/turborepo","slug":"unexpected-error-reading-package-json-at-works","errorCode":null,"errorMessage":"unexpected error reading \"package.json\" at ${workspaceRoot}","messagePattern":"unexpected error reading \"package\\.json\" at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/turbo-workspaces/src/utils.ts","lineNumber":77,"sourceCode":"  try {\n    return readJsonSync(packageJsonPath, \"utf8\") as PackageJson;\n  } catch (err) {\n    if (err && typeof err === \"object\" && \"code\" in err) {\n      if (err.code === \"ENOENT\") {\n        throw new ConvertError(`no \"package.json\" found at ${workspaceRoot}`, {\n          type: \"package_json-missing\"\n        });\n      }\n      if (err.code === \"EJSONPARSE\") {\n        throw new ConvertError(\n          `failed to parse \"package.json\" at ${workspaceRoot}`,\n          {\n            type: \"package_json-parse_error\"\n          }\n        );\n      }\n    }\n    throw new Error(\n      `unexpected error reading \"package.json\" at ${workspaceRoot}`\n    );\n  }\n}\n\nfunction getWorkspacePackageManager({\n  workspaceRoot\n}: {\n  workspaceRoot: string;\n}): PackageManager | undefined {\n  const packageJson = getPackageJson({ workspaceRoot });\n  const { packageManager, devEngines } = packageJson;\n  if (packageManager) {\n    try {\n      const match = PACKAGE_MANAGER_REGEX.exec(packageManager);\n      if (match) {\n        const manager = match.groups?.manager;\n        return isPackageManager(manager) ? manager : undefined;","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/vercel/turborepo/blob/f9245100cf0d31d96628804ead485f6bf226e55a/packages/turbo-workspaces/src/utils.ts#L59-L95","documentation":"The fallback branch of getPackageJson(): the thrown filesystem error had a code that was neither ENOENT nor EJSONPARSE (or had no code at all), so it is rethrown as a plain Error `unexpected error reading \"package.json\"` with no ConvertError type. It covers every other IO failure the OS can produce while reading the manifest.","triggerScenarios":"EACCES/EPERM because package.json is not readable by the current user; EISDIR because package.json is actually a directory; EMFILE from file-descriptor exhaustion; exotic errors on network filesystems.","commonSituations":"Permission/ownership mismatches in Docker or CI volumes; a directory accidentally named package.json; processes leaking fds before the read; NFS/SMB mounts returning nonstandard errors.","solutions":["Check the entry type: `ls -la package.json` must be a file, not a directory","Fix read permissions: chmod 644 package.json (and chown if another user owns it)","If running inside Docker/CI, verify the volume mount gives the runtime user read access","Raise the file-descriptor limit (ulimit -n) if you suspect EMFILE"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { statSync } from \"node:fs\";\nconst st = statSync(manifestPath); // throws ENOENT if missing — handle separately\nif (!st.isFile()) throw new Error(\"package.json is a directory\");\nprocess.accessSync?.(manifestPath, fsConstants.R_OK); // verify readability","typeGuard":"function isUnexpectedReadError(e: unknown): e is Error {\n  return e instanceof Error && !(typeof e === \"object\" && \"type\" in e);\n}","tryCatchPattern":"try {\n  await readWorkspace(args);\n} catch (e) {\n  // this branch throws a plain Error with no `type` — inspect the original\n  // filesystem cause (permissions, EISDIR, EMFILE) and report it verbatim\n  if (e instanceof Error && !(\"type\" in e)) {\n    log.error(`filesystem problem reading package.json: ${e.message}`);\n  }\n}","preventionTips":["Verify package.json is a regular file with read permission before batch operations","In Docker/CI, mount repositories so the runtime user can read all manifests","Watch for fd exhaustion (EMFILE) when processing many workspaces — raise ulimit -n"],"tags":["package-json","filesystem","permissions","io-error"],"backgroundTag":"package-json-read-error","analyzedSha":"f9245100cf0d31d96628804ead485f6bf226e55a","analyzedAt":"2026-08-17T10:46:15.696Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}