{"record":{"id":"b50de3eeb92a285e","repo":"yarnpkg/yarn","slug":"directory-0-doesn-t-exist","errorCode":null,"errorMessage":"Directory $0 doesn't exist","messagePattern":"Directory \\$0 doesn't exist","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/config.js","lineNumber":777,"sourceCode":"  }\n\n  async findManifest(dir: string, isRoot: boolean): Promise<?Manifest> {\n    for (const registry of registryNames) {\n      const manifest = await this.tryManifest(dir, registry, isRoot);\n\n      if (manifest) {\n        return manifest;\n      }\n    }\n\n    return null;\n  }\n\n  async findWorkspaceRoot(initial: string): Promise<?string> {\n    let previous = null;\n    let current = path.normalize(initial);\n    if (!await fs.exists(current)) {\n      throw new MessageError(this.reporter.lang('folderMissing', current));\n    }\n\n    do {\n      const manifest = await this.findManifest(current, true);\n      const ws = extractWorkspaces(manifest);\n      if (ws && ws.packages) {\n        const relativePath = path.relative(current, initial);\n        if (relativePath === '' || micromatch([relativePath], ws.packages).length > 0) {\n          return current;\n        } else {\n          return null;\n        }\n      }\n\n      previous = current;\n      current = path.dirname(current);\n    } while (current !== previous);\n","sourceCodeStart":759,"sourceCodeEnd":795,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/config.js#L759-L795","documentation":"Thrown by `findWorkspaceRoot` when the initial cwd path does not exist on disk (`fs.exists(current)` is false). Before walking up the tree looking for a workspace root, Yarn confirms the starting directory is real; if it is not, it fails fast rather than walking phantom paths.","triggerScenarios":"The process cwd was deleted, unmounted, or renamed out from under the running Yarn process. Passing a non-existent `--cwd` value. A script `cd`s into a dir then it is removed before Yarn starts.","commonSituations":"A build step deletes and recreates the working directory while Yarn is spawned. tmux/IDE session retains a stale cwd after the dir was removed. Typo in a wrapper script's `cd` target.","solutions":["Verify the directory exists before running Yarn: `test -d \"$PWD\" || cd ~`.","Recreate or `cd` into a valid directory before invoking Yarn.","Check that any `--cwd` flag points to an existing path.","Avoid deleting the cwd in a preinstall/postinstall hook."],"exampleFix":"# before\nyarn install  # cwd was just rm -rf'd\n# after\ncd /valid/project/dir\nyarn install","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst cwd = process.cwd();\nif (!fs.existsSync(cwd)) {\n  console.error(`cwd '${cwd}' does not exist. Re-run from a valid directory.`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await config.findWorkspaceRoot(initial);\n} catch (err) {\n  if (err instanceof MessageError && err.message.includes(\"doesn't exist\")) {\n    process.chdir(process.env.HOME || '/tmp');\n    throw new Error(`Working directory was removed — restarted in a valid cwd.`);\n  }\n  throw err;\n}","preventionTips":["Never delete the process cwd in preinstall/postinstall hooks.","Validate `process.cwd()` exists at the start of wrapper scripts.","Avoid `rm -rf` on directories containing the running shell session."],"tags":["filesystem","workspaces","cwd"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}