angular/angular-cli · error · CommandModuleError
This command is not available when running the Angular CLI $
Error message
This command is not available when running the Angular CLI ${workspace ? 'inside' : 'outside'} a workspace. What it means
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.
Source
Thrown at packages/angular/cli/src/command-builder/utilities/command.ts:53
const describe = jsonHelp ? cmd.fullDescribe : cmd.describe;
context.yargsInstance.command({
command: cmd.command,
aliases: cmd.aliases,
describe:
// We cannot add custom fields in help, such as long command description which is used in AIO.
// Therefore, we get around this by adding a complex object as a string which we later parse when generating the help files.
typeof describe === 'object' ? JSON.stringify(describe) : describe,
deprecated: cmd.deprecated,
builder: (argv) => {
// Skip scope validation when running with '--json-help' since it's easier to generate the output for all commands this way.
const isInvalidScope =
!jsonHelp &&
((cmd.scope === CommandScope.In && !workspace) ||
(cmd.scope === CommandScope.Out && workspace));
if (isInvalidScope) {
throw new CommandModuleError(
`This command is not available when running the Angular CLI ${
workspace ? 'inside' : 'outside'
} a workspace.`,
);
}
return cmd.builder(argv) as Argv;
},
handler: (args) => cmd.handler(args),
});
}
View on GitHub (pinned to bb72145f9a)
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
Example fix
// before (inside a workspace) ng new other-app // after cd .. && ng new other-app
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'fs';
import { CommandScope } from '@angular/cli/src/command-builder/command-builder';
function scopeMatches(cmdScope: 'in' | 'out'): boolean {
const inWorkspace = existsSync('angular.json');
return cmdScope === 'in' ? inWorkspace : !inWorkspace;
}
if (!scopeMatches(cmd.scope)) process.chdir(correctDir); Try / catch
try {
await runCommand(args);
} catch (e) {
const m = /not available when running the Angular CLI (inside|outside) a workspace/.exec(String(e));
if (m) {
console.error(`Wrong location: you are ${m[1]} a workspace for this command.`);
process.exit(1);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: '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.
Related errors
- A workspace is required for this command.
- Could not find ${level} workspace.
- Could not find a ${level} workspace. Are you in a project?
- Cannot determine project for command. This is a multi-projec
- Cannot retrieve cache configuration as workspace is not defi
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/39c361d13030044f.
Report an issue: GitHub.