Skip to content

Commit 5267e60

Browse files
committed
fix(@angular/cli): handle packages with no version
In some cases pacote will return undefined as `version` which resulted in `Cannot convert undefined or null to object`. Closes #26337 (cherry picked from commit bec9458)
1 parent 5623c19 commit 5267e60

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/angular/cli/src/utilities/package-metadata.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ export async function fetchPackageMetadata(
249249
...(registry ? { registry } : {}),
250250
});
251251

252+
if (!response.versions) {
253+
// While pacote type declares that versions cannot be undefined this is not the case.
254+
response.versions = {};
255+
}
256+
252257
// Normalize the response
253258
const metadata: PackageMetadata = {
254259
...response,
@@ -312,6 +317,13 @@ export async function getNpmPackageJson(
312317
fullMetadata: true,
313318
...npmrc,
314319
...(registry ? { registry } : {}),
320+
}).then((response) => {
321+
// While pacote type declares that versions cannot be undefined this is not the case.
322+
if (!response.versions) {
323+
response.versions = {};
324+
}
325+
326+
return response;
315327
});
316328

317329
npmPackageJsonCache.set(packageName, response);

0 commit comments

Comments
 (0)