{"record":{"id":"1c1fd011051a0feb","repo":"nodejs/node","slug":"workspaces-not-supported-for-global-packages","errorCode":null,"errorMessage":"Workspaces not supported for global packages","messagePattern":"Workspaces not supported for global packages","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/npm.js","lineNumber":281,"sourceCode":"      const subcommandPath = [...commandPath, subcommandName]\n\n      return time.start(`command:${subcommandPath.join(':')}`, () =>\n        this.execCommandClass(subcommandInstance, subcommandArgs, subcommandPath))\n    }\n\n    // No subcommands - execute this command\n    if (this.config.get('usage')) {\n      return output.standard(commandInstance.usage)\n    }\n\n    let execWorkspaces = false\n    const hasWsConfig = this.config.get('workspaces') || this.config.get('workspace').length\n    // if cwd is a workspace, the default is set to [that workspace]\n    const implicitWs = this.config.get('workspace', 'default').length\n    // (-ws || -w foo) && (cwd is not a workspace || command is not ignoring implicit workspaces)\n    if (hasWsConfig && (!implicitWs || !Command.ignoreImplicitWorkspace)) {\n      if (this.global) {\n        throw new Error('Workspaces not supported for global packages')\n      }\n      if (!Command.workspaces) {\n        throw Object.assign(new Error('This command does not support workspaces.'), {\n          code: 'ENOWORKSPACES',\n        })\n      }\n      execWorkspaces = true\n    }\n\n    // Check dev engines if needed\n    if (commandInstance.checkDevEngines && !this.global) {\n      await commandInstance.checkDevEngines()\n    }\n\n    // Execute command with or without definitions\n    if (Command.definitions) {\n      // config.argv contains the full argv with flags (set by Config in production, by MockNpm in tests)\n      // Pass depth so flags() knows how many command names to skip","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/npm.js#L263-L299","documentation":"Thrown by npm's central command executor when the user passed a workspace option (`--workspaces`/`-ws`, or `--workspace`/`-w`) and the resolved target would operate on global packages. Workspaces are a per-project concept rooted in a local package.json, so combining them with `--global` is contradictory and rejected before the command runs.","triggerScenarios":"`npm install -g --workspace=foo pkg`, or any command under `npm -g -ws`, or having `global=true` plus `workspaces=true` in config. The guard fires when hasWsConfig is true and (!implicitWs || !ignoreImplicitWorkspace).","commonSituations":"An .npmrc sets `workspaces=true` and a script invokes `npm -g`; CI that sets both flags via env vars; aliasing `-ws` globally and forgetting to disable it for global operations.","solutions":["Drop the workspace flag(s) when running globally.","Drop `-g`/`--global` when operating on workspaces.","Audit .npmrc and environment for stale `workspaces`/`global` settings; unset `npm_config_workspaces` in CI scripts."],"exampleFix":"// before\nnpm install -g --workspace=app lodash\n// after\nnpm install --workspace=app lodash   // local\n// or\nnpm install -g lodash               // global, no workspace","handlingStrategy":"validation","validationCode":"const hasWs = npm.config.get('workspaces') || npm.config.get('workspace').length\nif (hasWs && npm.config.get('global')) {\n  throw new Error('Workspaces cannot be combined with global mode')\n}","typeGuard":"const isWorkspaceGlobalConflict = (cfg) =>\n  (cfg.get('workspaces') || cfg.get('workspace').length > 0) && cfg.get('global')","tryCatchPattern":"try {\n  await npm.exec(cmd, args)\n} catch (err) {\n  if (/Workspaces not supported for global/i.test(err.message)) {\n    // drop either the -ws/-w flag or the -g flag based on user intent, then retry\n  } else { throw err }\n}","preventionTips":["Keep `workspaces` out of global .npmrc to avoid surprising CI failures.","Audit npm_config_* environment variables in CI for stale workspace/global settings.","Separate global and workspace commands into distinct steps."],"tags":["validation","workspaces","global","config"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}