{"record":{"id":"35c2a595cd07d909","repo":"yarnpkg/yarn","slug":"yarn-hasn-t-been-able-to-find-a-cache-folder-it-ca","errorCode":null,"errorMessage":"Yarn hasn't been able to find a cache folder it can use. Please use the explicit --cache-folder option to tell it what location to use, or make one of the preferred locations writable.","messagePattern":"Yarn hasn't been able to find a cache folder it can use\\. Please use the explicit --cache-folder option to tell it what location to use, or make one of the preferred locations writable\\.","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/config.js","lineNumber":377,"sourceCode":"        preferredCacheFolders = [String(preferredCacheFolder)].concat(preferredCacheFolders);\n      }\n\n      const cacheFolderQuery = await fs.getFirstSuitableFolder(\n        preferredCacheFolders,\n        fs.constants.W_OK | fs.constants.X_OK | fs.constants.R_OK, // eslint-disable-line no-bitwise\n      );\n      for (const skippedEntry of cacheFolderQuery.skipped) {\n        this.reporter.warn(this.reporter.lang('cacheFolderSkipped', skippedEntry.folder));\n      }\n\n      cacheRootFolder = cacheFolderQuery.folder;\n      if (cacheRootFolder && cacheFolderQuery.skipped.length > 0) {\n        this.reporter.warn(this.reporter.lang('cacheFolderSelected', cacheRootFolder));\n      }\n    }\n\n    if (!cacheRootFolder) {\n      throw new MessageError(this.reporter.lang('cacheFolderMissing'));\n    } else {\n      this._cacheRootFolder = String(cacheRootFolder);\n    }\n\n    const manifest = await this.maybeReadManifest(this.lockfileFolder);\n\n    const plugnplayByEnv = this.getOption('plugnplay-override');\n    if (plugnplayByEnv != null) {\n      this.plugnplayEnabled = plugnplayByEnv !== 'false' && plugnplayByEnv !== '0';\n      this.plugnplayPersist = false;\n    } else if (opts.enablePnp || opts.disablePnp) {\n      this.plugnplayEnabled = !!opts.enablePnp;\n      this.plugnplayPersist = true;\n    } else if (manifest && manifest.installConfig && manifest.installConfig.pnp) {\n      this.plugnplayEnabled = !!manifest.installConfig.pnp;\n      this.plugnplayPersist = false;\n    } else {\n      this.plugnplayEnabled = false;","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/config.js#L359-L395","documentation":"Thrown when Yarn cannot locate any writable cache folder. Yarn first honors `--cache-folder` / `cache-folder` option, then probes `constants.PREFERRED_MODULE_CACHE_DIRECTORIES` (e.g. ~/.cache/yarn, XDG dirs) for write+execute+read access via `getFirstSuitableFolder`. If none is writable, `cacheRootFolder` stays falsy and this error fires.","triggerScenarios":"All preferred cache directories are read-only or non-creatable (locked-down environment, container with read-only home, restricted CI runner), and no explicit `--cache-folder` was passed.","commonSituations":"CI containers where $HOME is read-only. Docker images running as a non-root user without a writable home. Systems where XDG_CACHE_HOME points to an unwritable path. Disk-full conditions.","solutions":["Pass `--cache-folder <writable-path>` on the command line.","Set `cache-folder \"<path>\"` in .yarnrc.","Ensure $HOME or XDG_CACHE_HOME is writable by the current user (`chmod`/`chown`).","In containers, create and chmod a cache dir, then point Yarn at it: `mkdir -p /tmp/yarn-cache && yarn --cache-folder /tmp/yarn-cache`."],"exampleFix":"# before\nyarn install\n# after\nyarn install --cache-folder /tmp/yarn-cache\n# or in .yarnrc:\n# cache-folder \"/tmp/yarn-cache\"","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst path = require('path');\n\nfunction findWritableCacheFolder(candidates) {\n  for (const dir of candidates) {\n    try {\n      fs.mkdirSync(dir, {recursive: true});\n      fs.accessSync(dir, fs.constants.W_OK | fs.constants.X_OK | fs.constants.R_OK);\n      return dir;\n    } catch {}\n  }\n  return null;\n}\n\nconst cache = findWritableCacheFolder([\n  process.env.XDG_CACHE_HOME && path.join(process.env.XDG_CACHE_HOME, 'yarn'),\n  path.join(process.env.HOME || '/tmp', '.cache', 'yarn'),\n  '/tmp/yarn-cache',\n]);\nif (!cache) {\n  console.error('No writable cache folder — pass --cache-folder <path>.');\n  process.exit(1);\n}\nprocess.env.YARN_CACHE_FOLDER = cache;","typeGuard":null,"tryCatchPattern":"try {\n  await config.init(opts);\n} catch (err) {\n  if (err.message.includes('cache folder')) {\n    // retry with an explicit writable temp cache folder\n    opts.cacheFolder = '/tmp/yarn-cache';\n    await fs.mkdirp(opts.cacheFolder);\n    await config.init(opts);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Set `cache-folder` explicitly in .yarnrc for CI and containers.","Ensure $HOME or XDG_CACHE_HOME is writable before running Yarn.","In Docker, create and chown the cache directory in the image."],"tags":["cache","filesystem","permissions","config"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}