{"record":{"id":"4cb241107c1e4290","repo":"yarnpkg/yarn","slug":"couldntfindpackageincache","errorCode":null,"errorMessage":"couldntFindPackageInCache","messagePattern":"couldntFindPackageInCache","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/resolvers/registries/npm-resolver.js","lineNumber":140,"sourceCode":"        continue;\n      }\n\n      // read package metadata\n      const metadata = await this.config.readPackageMetadata(dir);\n      if (!metadata.remote) {\n        continue; // old yarn metadata\n      }\n\n      versions[pkg.version] = Object.assign({}, pkg, {\n        _remote: metadata.remote,\n      });\n    }\n\n    const satisfied = await this.config.resolveConstraints(Object.keys(versions), this.range);\n    if (satisfied) {\n      return versions[satisfied];\n    } else if (!this.config.preferOffline) {\n      throw new MessageError(\n        this.reporter.lang('couldntFindPackageInCache', this.name, this.range, Object.keys(versions).join(', ')),\n      );\n    } else {\n      return null;\n    }\n  }\n\n  cleanRegistry(url: string): string {\n    if (this.config.getOption('registry') === YARN_REGISTRY) {\n      return url.replace(NPM_REGISTRY_RE, YARN_REGISTRY);\n    } else {\n      return url;\n    }\n  }\n\n  async resolve(): Promise<Manifest> {\n    // lockfile\n    const shrunk = this.request.getLocked('tarball');","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/resolvers/registries/npm-resolver.js#L122-L158","documentation":"During offline resolution, if no cached version satisfies the range (resolveConstraints returns null) and preferOffline is false, Yarn throws because it cannot reach the network and has no matching cache entry.","triggerScenarios":"Running with --offline (config.offline true) where the cache lacks any version satisfying the requested range. The else-if (!preferOffline) branch throws.","commonSituations":"CI without network access; air-gapped environments; stale cache after a version bump that was never fetched online.","solutions":["Run yarn install online first to populate the cache","Remove the --offline flag to allow network resolution","Run yarn cache clean followed by a fresh online install","Use --prefer-offline instead of --offline to allow fallback to network"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Verify cache has a satisfying version before going offline\nconst cachedVersions = await getCachedVersions(config, name);\nif (!semver.maxSatisfying(cachedVersions, range)) {\n  console.warn(`No cached version of ${name} satisfies ${range}; online install needed`);\n}","typeGuard":"function cacheSatisfies(cachedVersions: string[], range: string): boolean {\n  return semver.maxSatisfying(cachedVersions, range) !== null;\n}","tryCatchPattern":"try {\n  const manifest = await resolver.resolveRequestOffline();\n} catch (e) {\n  if (e.message.includes('couldntFindPackageInCache')) {\n    // retry without --offline to fetch from the network\n  }\n}","preventionTips":["Run a full online install before entering offline mode","Use --prefer-offline instead of --offline to permit network fallback","Warm the cache for all required version ranges in CI images"],"tags":["offline","cache","resolution"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}