Skip to content

Commit 97ffd2d

Browse files
committed
fix(@angular/cli): handle missing package manager during analytics initialization
Wrap getVersion() call in try-catch to prevent a crash during analytics setup when the package manager is not available.
1 parent 7fbc715 commit 97ffd2d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,17 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
153153
['version', 'update', 'analytics'].includes(this.commandName),
154154
);
155155

156+
let version: string | undefined;
157+
try {
158+
version = await this.context.packageManager.getVersion();
159+
} catch {
160+
// Ignore errors if the package manager is not available.
161+
}
162+
156163
return userId
157164
? new AnalyticsCollector(this.context.logger, userId, {
158165
name: this.context.packageManager.name,
159-
version: await this.context.packageManager.getVersion(),
166+
version,
160167
})
161168
: undefined;
162169
}

0 commit comments

Comments
 (0)