Skip to content

Commit dbe0dc1

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular/cli): improve error message for project-specific ng commands when run outside of a project
With this change we improve the error message when a project for command cannot be determined ``` Error: Cannot determine project for command. This is a multi-project workspace and more than one project supports this command. Run "ng build [project]" to execute the command for a specific project or change the current working directory to a project directory. Available projects are: - project-name-0 - project-name-1 - project-name-2 - project-name-3 - project-name-4 - project-name-5 - project-name-6 - project-name-7 - project-name-8 - project-name-9 ``` Closes #23481
1 parent 53e9c45 commit dbe0dc1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/angular/cli/src/command-builder/architect-command-module.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ export abstract class ArchitectCommandModule
144144
if (!getYargsCompletions && !help) {
145145
// Only issue the below error when not in help / completion mode.
146146
throw new CommandModuleError(
147-
'Cannot determine project for command. ' +
148-
'Pass the project name as a command line argument or change the current working directory to a project directory.',
147+
'Cannot determine project for command.\n' +
148+
'This is a multi-project workspace and more than one project supports this command. ' +
149+
`Run "ng ${this.command}" to execute the command for a specific project or change the current ` +
150+
'working directory to a project directory.\n\n' +
151+
`Available projects are:\n${allProjectsForTargetName
152+
.sort()
153+
.map((p) => `- ${p}`)
154+
.join('\n')}`,
149155
);
150156
}
151157
}

tests/legacy-cli/e2e/tests/commands/project-cannot-be-determined-by-cwd.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { join } from 'path';
2-
import { expectFileNotToExist, expectFileToExist } from '../../utils/fs';
32
import { execAndWaitForOutputToMatch, ng } from '../../utils/process';
43
import { updateJsonFile } from '../../utils/project';
54
import { expectToFail } from '../../utils/utils';
65

76
export default async function () {
87
const errorMessage =
9-
'Cannot determine project for command. ' +
10-
'Pass the project name as a command line argument or change the current working directory to a project directory';
8+
'Cannot determine project for command.\n' +
9+
'This is a multi-project workspace and more than one project supports this command.';
1110

1211
// Delete root project
1312
await updateJsonFile('angular.json', (workspaceJson) => {

0 commit comments

Comments
 (0)