{"record":{"id":"39c361d13030044f","repo":"angular/angular-cli","slug":"this-command-is-not-available-when-running-the-ang","errorCode":null,"errorMessage":"This command is not available when running the Angular CLI ${workspace ? 'inside' : 'outside'} a workspace.","messagePattern":"This command is not available when running the Angular CLI (.+?) a workspace\\.","errorType":"exception","errorClass":"CommandModuleError","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/command-builder/utilities/command.ts","lineNumber":53,"sourceCode":"  const describe = jsonHelp ? cmd.fullDescribe : cmd.describe;\n\n  context.yargsInstance.command({\n    command: cmd.command,\n    aliases: cmd.aliases,\n    describe:\n      // We cannot add custom fields in help, such as long command description which is used in AIO.\n      // Therefore, we get around this by adding a complex object as a string which we later parse when generating the help files.\n      typeof describe === 'object' ? JSON.stringify(describe) : describe,\n    deprecated: cmd.deprecated,\n    builder: (argv) => {\n      // Skip scope validation when running with '--json-help' since it's easier to generate the output for all commands this way.\n      const isInvalidScope =\n        !jsonHelp &&\n        ((cmd.scope === CommandScope.In && !workspace) ||\n          (cmd.scope === CommandScope.Out && workspace));\n\n      if (isInvalidScope) {\n        throw new CommandModuleError(\n          `This command is not available when running the Angular CLI ${\n            workspace ? 'inside' : 'outside'\n          } a workspace.`,\n        );\n      }\n\n      return cmd.builder(argv) as Argv;\n    },\n    handler: (args) => cmd.handler(args),\n  });\n}\n","sourceCodeStart":35,"sourceCodeEnd":65,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/command-builder/utilities/command.ts#L35-L65","documentation":"Each Angular CLI command declares a scope: CommandScope.In (only inside a workspace) or CommandScope.Out (only outside). addCommandModuleToYargs enforces this when registering commands and throws this error indicating whether you were 'inside' or 'outside' a workspace.","triggerScenarios":"Running an inside-only command (e.g. 'ng serve', 'ng generate') outside a workspace, or an outside-only command (e.g. 'ng new', 'ng add' historically) inside a workspace. Suppressed when --json-help is used.","commonSituations":"'ng serve' in a plain Node repo; 'ng new' executed inside an existing Angular workspace; running global 'ng' from $HOME; IDE terminals defaulting to the wrong directory.","solutions":["cd into (or out of) the appropriate directory: workspace commands need angular.json present","Run 'ng new my-app' from outside a workspace, then cd into it","Check 'pwd' — IDE terminals often open at the workspace root of a monorepo, not the app","Use the correct command variant for your location, or wrap in npm scripts executed at the right cwd"],"exampleFix":"// before (inside a workspace)\nng new other-app\n// after\ncd .. && ng new other-app","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs';\nimport { CommandScope } from '@angular/cli/src/command-builder/command-builder';\n\nfunction scopeMatches(cmdScope: 'in' | 'out'): boolean {\n  const inWorkspace = existsSync('angular.json');\n  return cmdScope === 'in' ? inWorkspace : !inWorkspace;\n}\nif (!scopeMatches(cmd.scope)) process.chdir(correctDir);","typeGuard":null,"tryCatchPattern":"try {\n  await runCommand(args);\n} catch (e) {\n  const m = /not available when running the Angular CLI (inside|outside) a workspace/.exec(String(e));\n  if (m) {\n    console.error(`Wrong location: you are ${m[1]} a workspace for this command.`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Know each command's scope: 'new' outside, 'serve/generate/build' inside","Check pwd in IDE terminals; they often open at the monorepo root","Wrap location-sensitive commands in npm scripts run from a fixed cwd"],"tags":["angular-cli","command-scope","workspace"],"backgroundTag":"command-scope-violation","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}