{"record":{"id":"8e5f02a979383bbb","repo":"yarnpkg/yarn","slug":"this-command-can-only-be-run-inside-an-individual","errorCode":null,"errorMessage":"This command can only be run inside an individual workspace.","messagePattern":"This command can only be run inside an individual workspace\\.","errorType":"validation","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/config.js","lineNumber":260,"sourceCode":"   */\n\n  resolveConstraints(versions: Array<string>, range: string): Promise<?string> {\n    return this.constraintResolver.reduce(versions, range);\n  }\n\n  /**\n   * Initialise config. Fetch registry options, find package roots.\n   */\n\n  async init(opts: ConfigOptions = {}): Promise<void> {\n    this._init(opts);\n\n    this.workspaceRootFolder = await this.findWorkspaceRoot(this.cwd);\n    this.lockfileFolder = this.workspaceRootFolder || this.cwd;\n\n    // using focus in a workspace root is not allowed\n    if (this.focus && (!this.workspaceRootFolder || this.cwd === this.workspaceRootFolder)) {\n      throw new MessageError(this.reporter.lang('workspacesFocusRootCheck'));\n    }\n\n    if (this.focus) {\n      const focusedWorkspaceManifest = await this.readRootManifest();\n      this.focusedWorkspaceName = focusedWorkspaceManifest.name;\n    }\n\n    this.linkedModules = [];\n\n    let linkedModules;\n    try {\n      linkedModules = await fs.readdir(this.linkFolder);\n    } catch (err) {\n      if (err.code === 'ENOENT') {\n        linkedModules = [];\n      } else {\n        throw err;\n      }","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/config.js#L242-L278","documentation":"Thrown during `config.init` when the `--focus` flag is set and either no `workspaceRootFolder` was found (not inside a workspace) or `cwd === workspaceRootFolder` (you are AT the workspace root). Focus mode installs only the dependencies of one workspace plus shared deps, so it must be run from within an individual workspace sub-package, not the root.","triggerScenarios":"Running `yarn install --focus` from the workspace root directory. Running `--focus` outside any workspace project at all.","commonSituations":"Developer reads about `--focus` and tries it from the repo root. CI script sets `--focus` globally but runs from root. Migrating from a focused workspace setup and forgetting to `cd` into the package.","solutions":["Change directory into an individual workspace package before running `yarn install --focus`.","Remove the `--focus` flag if you want a full root install.","Verify `config.cwd !== config.workspaceRootFolder` before invoking focus."],"exampleFix":"# before (run from repo root)\nyarn install --focus\n# after\ncd packages/my-workspace\nyarn install --focus","handlingStrategy":"validation","validationCode":"// Before running with --focus, ensure cwd is inside a workspace but not at its root.\nif (config.focus) {\n  if (!config.workspaceRootFolder) {\n    throw new Error('--focus requires being inside an individual workspace (no workspace root found).');\n  }\n  if (config.cwd === config.workspaceRootFolder) {\n    throw new Error('--focus must be run from a workspace sub-package, not the root.');\n  }\n}","typeGuard":"function isInsideWorkspaceNotRoot(config) {\n  return Boolean(config.workspaceRootFolder) && config.cwd !== config.workspaceRootFolder;\n}","tryCatchPattern":"try {\n  await config.init({focus: true});\n} catch (err) {\n  if (err.message.includes('workspacesFocusRootCheck')) {\n    console.error('cd into a workspace package before using --focus.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Always `cd` into the target workspace package before running `yarn install --focus`.","In monorepo task runners, assert `process.cwd() !== workspaceRoot` before adding `--focus`.","Document that --focus is a per-workspace operation."],"tags":["workspaces","focus","install"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}