Skip to content

Commit eda96de

Browse files
alan-agius4dgp1130
authored andcommittedNov 16, 2022
fix(@angular/cli): use global version of the CLI when running ng new
In some cases orphan `node_modules` would cause the non global CLI to be used to generate a new workspace. Closes #14603 (cherry picked from commit 412cb3e)
1 parent 5cb23f9 commit eda96de

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎packages/angular/cli/lib/init.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ let forceExit = false;
3333
* See: https://github.com/browserslist/browserslist/blob/819c4337456996d19db6ba953014579329e9c6e1/node.js#L324
3434
*/
3535
process.env.BROWSERSLIST_IGNORE_OLD_DATA = '1';
36+
const rawCommandName = process.argv[2];
3637

3738
/**
3839
* Disable CLI version mismatch checks and forces usage of the invoked CLI
3940
* instead of invoking the local installed version.
41+
*
42+
* When running `ng new` always favor the global version. As in some
43+
* cases orphan `node_modules` would cause the non global CLI to be used.
44+
* @see: https://github.com/angular/angular-cli/issues/14603
4045
*/
41-
if (disableVersionCheck) {
46+
if (disableVersionCheck || rawCommandName === 'new') {
4247
return (await import('./cli')).default;
4348
}
4449

4550
let cli;
46-
const rawCommandName = process.argv[2];
4751

4852
try {
4953
// No error implies a projectLocalCli, which will load whatever

0 commit comments

Comments
 (0)