{"record":{"id":"630bc8ed9304100f","repo":"yarnpkg/yarn","slug":"workspacerootnotfound","errorCode":null,"errorMessage":"workspaceRootNotFound","messagePattern":"workspaceRootNotFound","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/workspace.js","lineNumber":21,"sourceCode":"import type Config from '../../config.js';\nimport {MessageError} from '../../errors.js';\nimport type {Reporter} from '../../reporters/index.js';\nimport * as child from '../../util/child.js';\nimport {NODE_BIN_PATH, YARN_BIN_PATH} from '../../constants';\n\nconst invariant = require('invariant');\n\nexport function setFlags(commander: Object) {}\n\nexport function hasWrapper(commander: Object, args: Array<string>): boolean {\n  return true;\n}\n\nexport async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {\n  const {workspaceRootFolder} = config;\n\n  if (!workspaceRootFolder) {\n    throw new MessageError(reporter.lang('workspaceRootNotFound', config.cwd));\n  }\n\n  if (args.length < 1) {\n    throw new MessageError(reporter.lang('workspaceMissingWorkspace'));\n  }\n\n  if (args.length < 2) {\n    throw new MessageError(reporter.lang('workspaceMissingCommand'));\n  }\n\n  const manifest = await config.findManifest(workspaceRootFolder, false);\n  invariant(manifest && manifest.workspaces, 'We must find a manifest with a \"workspaces\" property');\n\n  const workspaces = await config.resolveWorkspaces(workspaceRootFolder, manifest);\n  const [workspaceName, ...rest] = args || [];\n\n  if (!Object.prototype.hasOwnProperty.call(workspaces, workspaceName)) {\n    throw new MessageError(reporter.lang('workspaceUnknownWorkspace', workspaceName));","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/workspace.js#L3-L39","documentation":"Thrown by 'yarn workspace' when config.workspaceRootFolder is falsy. Yarn walks up from cwd looking for a manifest declaring a 'workspaces' field; if none is found, there is no workspace root to operate from.","triggerScenarios":"Running 'yarn workspace <name> <cmd>' in a directory tree whose root package.json has no 'workspaces' field (or where cwd is outside the project entirely).","commonSituations":"Not a monorepo; root package.json is missing the 'workspaces' key; running from a temp/external directory; using the wrong Yarn version that does not auto-detect workspaces.","solutions":["Run the command from inside the workspace project root.","Add a 'workspaces' field (array of globs) to the root package.json and run 'yarn install'.","Confirm the project actually intends to use workspaces."],"exampleFix":"// before (root package.json)\n{ \"name\": \"root\", \"private\": true }\n// after\n{\n  \"name\": \"root\",\n  \"private\": true,\n  \"workspaces\": [\"packages/*\"]\n}","handlingStrategy":"validation","validationCode":"if (!config.workspaceRootFolder) {\n  throw new Error(`No workspace root found from ${config.cwd}; add a 'workspaces' field to the root manifest.`);\n}","typeGuard":"function hasWorkspaceRoot(config: Config): boolean {\n  return typeof config.workspaceRootFolder === 'string' && config.workspaceRootFolder.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Confirm the root package.json declares 'workspaces' before running workspace commands.","Run workspace commands from the workspace root.","Add a CI check that 'workspaces' is defined for monorepo repos."],"tags":["workspaces","config","manifest"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}