Skip to content

Commit

Permalink
fix: cannot read properties of undefined (reading missingPeersOfChild…
Browse files Browse the repository at this point in the history
…ren)

close #8041
  • Loading branch information
zkochan committed May 6, 2024
1 parent 21de734 commit 7e6c9d2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/mighty-rats-suffer.md
@@ -0,0 +1,7 @@
---
"@pnpm/resolve-dependencies": patch
"@pnpm/lockfile-utils": patch
"pnpm": patch
---

Fix `Cannot read properties of undefined (reading 'missingPeersOfChildren')` exception that happens on install [#8041](https://github.com/pnpm/pnpm/issues/8041).
2 changes: 2 additions & 0 deletions lockfile/lockfile-utils/src/nameVerFromPkgSnapshot.ts
Expand Up @@ -5,6 +5,7 @@ export interface NameVer {
name: string
peersSuffix: string | undefined
version: string
nonSemverVersion?: string
}

export function nameVerFromPkgSnapshot (
Expand All @@ -16,5 +17,6 @@ export function nameVerFromPkgSnapshot (
name: pkgInfo.name as string,
peersSuffix: pkgInfo.peersSuffix,
version: pkgSnapshot.version ?? pkgInfo.version as string,
nonSemverVersion: pkgInfo.nonSemverVersion,
}
}
2 changes: 1 addition & 1 deletion pkg-manager/package-requester/src/packageRequester.ts
Expand Up @@ -287,7 +287,7 @@ async function resolveAndFetch (
isLocal: false as const,
isInstallable: isInstallable ?? undefined,
latest,
manifest: manifest ?? (await fetchResult.fetching()).bundledManifest,
manifest,
normalizedPref,
resolution,
resolvedVia,
Expand Down
10 changes: 6 additions & 4 deletions pkg-manager/resolve-dependencies/src/resolveDependencies.ts
Expand Up @@ -12,7 +12,6 @@ import {
} from '@pnpm/lockfile-types'
import {
nameVerFromPkgSnapshot,
packageIdFromSnapshot,
pkgSnapshotToResolution,
} from '@pnpm/lockfile-utils'
import { logger } from '@pnpm/logger'
Expand Down Expand Up @@ -1047,19 +1046,22 @@ function getInfoFromLockfile (
}
}

const { name, version, nonSemverVersion } = nameVerFromPkgSnapshot(depPath, dependencyLockfile)
return {
...nameVerFromPkgSnapshot(depPath, dependencyLockfile),
name,
version,
dependencyLockfile,
depPath,
pkgId: packageIdFromSnapshot(depPath, dependencyLockfile),
pkgId: nonSemverVersion ?? `${name}@${version}`,
// resolution may not exist if lockfile is broken, and an unexpected error will be thrown
// if resolution does not exist, return undefined so it can be autofixed later
resolution: dependencyLockfile.resolution && pkgSnapshotToResolution(depPath, dependencyLockfile, registries),
}
} else {
const parsed = dp.parse(depPath)
return {
depPath,
pkgId: dp.tryGetPackageId(depPath) ?? depPath, // Does it make sense to set pkgId when we're not sure?
pkgId: parsed.nonSemverVersion ?? (parsed.name && parsed.version ? `${parsed.name}@${parsed.version}` : depPath), // Does it make sense to set pkgId when we're not sure?
}
}
}
Expand Down

0 comments on commit 7e6c9d2

Please sign in to comment.