Skip to content

fix(@angular/cli): improve error message for project-specific ng commands when run outside of a project #23484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ export abstract class ArchitectCommandModule
if (!getYargsCompletions && !help) {
// Only issue the below error when not in help / completion mode.
throw new CommandModuleError(
'Cannot determine project for command. ' +
'Pass the project name as a command line argument or change the current working directory to a project directory.',
'Cannot determine project for command.\n' +
'This is a multi-project workspace and more than one project supports this command. ' +
`Run "ng ${this.command}" to execute the command for a specific project or change the current ` +
'working directory to a project directory.\n\n' +
`Available projects are:\n${allProjectsForTargetName
.sort()
.map((p) => `- ${p}`)
.join('\n')}`,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { join } from 'path';
import { expectFileNotToExist, expectFileToExist } from '../../utils/fs';
import { execAndWaitForOutputToMatch, ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';

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

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