Skip to content

Commit 3347c6e

Browse files
committed
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 angular#23481
1 parent d6b9306 commit 3347c6e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,18 @@ export abstract class ArchitectCommandModule
143143
const { getYargsCompletions, help } = this.context.args.options;
144144
if (!getYargsCompletions && !help) {
145145
// Only issue the below error when not in help / completion mode.
146+
const maxProjectsToDisplay = 10;
146147
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.',
148+
'Cannot determine project for command.\n' +
149+
'This is a multi-project workspace and more than one project supports this command. ' +
150+
`Run "ng ${this.command}" to execute the command for a specific project or change the current ` +
151+
'working directory to a project directory.\n\n' +
152+
`Available projects are:\n${allProjectsForTargetName
153+
.slice(0, maxProjectsToDisplay)
154+
.sort()
155+
.map((p) => `- ${p}`)
156+
.join('\n')}` +
157+
(allProjectsForTargetName.length > maxProjectsToDisplay ? '\n...' : ''),
149158
);
150159
}
151160
}

0 commit comments

Comments
 (0)