{"record":{"id":"f0443bc099305a9f","repo":"yarnpkg/yarn","slug":"enoent","errorCode":"ENOENT","errorMessage":"Couldn't find a package.json file in $0","messagePattern":"Couldn't find a package\\.json file in \\$0","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/config.js","lineNumber":690,"sourceCode":"        remote: metadata.remote,\n        registry: metadata.registry,\n      };\n    });\n  }\n\n  /**\n   * Read normalized package info according yarn-metadata.json\n   * throw an error if package.json was not found\n   */\n\n  readManifest(dir: string, priorityRegistry?: RegistryNames, isRoot?: boolean = false): Promise<Manifest> {\n    return this.getCache(`manifest-${dir}`, async (): Promise<Manifest> => {\n      const manifest = await this.maybeReadManifest(dir, priorityRegistry, isRoot);\n\n      if (manifest) {\n        return manifest;\n      } else {\n        throw new MessageError(this.reporter.lang('couldntFindPackagejson', dir), 'ENOENT');\n      }\n    });\n  }\n\n  /**\n   * try get the manifest file by looking\n   * 1. manifest file in cache\n   * 2. manifest file in registry\n   */\n  async maybeReadManifest(dir: string, priorityRegistry?: RegistryNames, isRoot?: boolean = false): Promise<?Manifest> {\n    const metadataLoc = path.join(dir, constants.METADATA_FILENAME);\n\n    if (await fs.exists(metadataLoc)) {\n      const metadata = await this.readJson(metadataLoc);\n\n      if (!priorityRegistry) {\n        priorityRegistry = metadata.priorityRegistry;\n      }","sourceCodeStart":672,"sourceCodeEnd":708,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/config.js#L672-L708","documentation":"Thrown by `readManifest` (code 'ENOENT') when `maybeReadManifest` returns null for a directory — neither a yarn-metadata.json in cache nor a package.json under any registry filename was found. This is a hard failure variant of the soft null return; callers that require a manifest use `readManifest`, soft callers use `maybeReadManifest`.","triggerScenarios":"Calling `config.readManifest(dir)` where `dir` contains no package.json and no .yarn-metadata.json. Typically reached during install/link when a cache entry references a directory whose package.json was deleted, or when a workspace glob points at an empty/incomplete package.","commonSituations":"Corrupted or partially-deleted cache entry. A workspace folder exists but its package.json was removed. A dependency directory was truncated by an interrupted install. Manual deletion of node_modules contents.","solutions":["Run `yarn cache clean` and re-run `yarn install` to regenerate missing metadata.","Remove the offending `node_modules` directory and reinstall: `rm -rf node_modules && yarn install`.","If a workspace package is referenced, ensure its directory contains a valid package.json.","Inspect the `dir` value in the error to find which package is missing its manifest."],"exampleFix":"# before (broken cache/workspace)\nyarn install\n# after\nyarn cache clean\nrm -rf node_modules\nyarn install","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst path = require('path');\n\nasync function manifestExists(dir) {\n  const pkg = path.join(dir, 'package.json');\n  const meta = path.join(dir, '.yarn-metadata.json');\n  return fs.existsSync(pkg) || fs.existsSync(meta);\n}\n\nif (!(await manifestExists(targetDir))) {\n  console.error(`No package.json in ${targetDir} — run yarn install or restore the file.`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await config.readManifest(dir, priorityRegistry, isRoot);\n} catch (err) {\n  if (err.code === 'ENOENT' && err instanceof MessageError) {\n    // gracefully skip or trigger reinstall\n    await fs.unlink(dir).catch(() => {});\n    throw new Error(`Missing manifest at ${dir} — run yarn cache clean && yarn install`);\n  }\n  throw err;\n}","preventionTips":["Use `maybeReadManifest` (soft null) instead of `readManifest` when absence is tolerable.","Validate that workspace glob targets each contain a package.json before install.","Run `yarn cache clean` after corrupted or interrupted installs."],"tags":["manifest","cache","enoent","install"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}