pnpm icon indicating copy to clipboard operation
pnpm copied to clipboard

PNPM install prints "Cannot read properties of undefined (reading 'name')"

Open andschub-ms opened this issue 1 year ago • 7 comments

Verify latest release

  • [X] I verified that the issue exists in the latest pnpm release

pnpm version

9.10.0

Which area(s) of pnpm are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

No response

Reproduction steps

pnpm install

Describe the Bug

After pnpm install says it's finished, After postinstall hook says it's finished, usually at the part where it prints a bunch of warnings about peer dependencies, pnpm just prints the one line: "Cannot read properties of undefined (reading 'name')" There is no stack trace available.

We are using @pnpm/exe

The node_modules folder is populated after install -- but I'm concerned the process may have exited prematurely. Is there a way to set verbose logging or to debug exactly how this error is being printed?

Expected Behavior

I would normally expect to not see this error printed, and instead see a bunch of warnings about peer dependencies printed at the end.

EDIT: the issue repros in 9.10.0 but not 9.9.0, so the issue must have been introduced between versions.

Which Node.js version are you using?

Whatever is shipped with @pnpm/[email protected]

Which operating systems have you used?

  • [ ] macOS
  • [X] Windows
  • [ ] Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

No response

andschub-ms avatar Sep 16 '24 23:09 andschub-ms

I can confirm the bug. It happens on pnpm versions 9.10.0 and 9.11.0. It happens on MacOS as well.

Reproduction repo: https://github.com/VanTanev/pnpm-reproduce-8538

Here is a minimum reproduction setup:

package.json

{
    "name": "test",
    "packageManager": "[email protected]+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b",
    "dependencies": {
        "@udecode/plate-ui-table": "^18.13.0",
        "@udecode/plate-ui-toolbar": "^18.13.0"
    }
}

.npmrc

auto-install-peers = false

To replicate:

$ pnpm install # while no pnpm-lock.yaml exists
$ pnpm dedupe # if pnpm-lock.yaml exists

VanTanev avatar Sep 20 '24 22:09 VanTanev

also, for monorepo, in .npmrc shared-workspace-lockfile=false ✅ No error shared-workspace-lockfile=true ❌ Error

trydofor avatar Sep 26 '24 13:09 trydofor

Experiencing same thing on Linux/WSL2. Any ideas how to debug or get stacktrace?

GuskiS avatar Sep 28 '24 20:09 GuskiS

Hey @zkochan, I have bisected the breaking commit to: https://github.com/pnpm/pnpm/commit/96aa4bc4a3085ec886fd5d27d12e56584ab6bf0f

The root cause seems to be this: https://github.com/pnpm/pnpm/blob/9cfee8f46104f577af7fc8d6fdd69eddbd1ed2f2/pkg-manager/resolve-dependencies/src/resolvePeers.ts#L437-L445

parents can be empty, and it seems like in that case the issue should NOT be added, so maybe it needs to be:

 const { parents } = getLocationFromParentNodeIds(ctx) 
 if (!parents.length) continue

 if (ctx.peerDependencyIssues.missing[peerName] == null) { 
   ctx.peerDependencyIssues.missing[peerName] = [] 
 } 
 ...

The error is printed by this call: https://github.com/pnpm/pnpm/blob/9cfee8f46104f577af7fc8d6fdd69eddbd1ed2f2/pkg-manager/core/src/install/index.ts#L1361-L1364

And here is an example of the value of the peerDependencyIssuesByProjects variable that I see in my reproduction repository: https://gist.github.com/VanTanev/3f3325091f64d6bff447509842fa22a8 - search for "parents": []

I would contribute a PR, but I honestly don't understand the issue well enough, apologies.

VanTanev avatar Oct 06 '24 12:10 VanTanev

Since another bug introduced by https://github.com/pnpm/pnpm/commit/96aa4bc4a3085ec886fd5d27d12e56584ab6bf0f was recently fixed, I just wanted to say that the bug still exists in pnpm 9.12.1 and breaks install/dedupe.

VanTanev avatar Oct 08 '24 14:10 VanTanev

Experiencing the same here.

sneridagh avatar Oct 15 '24 08:10 sneridagh

Still present in 9.12.2

sneridagh avatar Oct 17 '24 06:10 sneridagh

@zkochan @KSXGitHub FYI this bug is install-blocking and affecting several users. @VanTanev was able to provide a minimal repro and isolate the part of the code as the root cause. Our organization will be prevented from upgrading PNPM from v9.9 until a fix or workaround is discovered. Thank you for your support.

andschub-ms avatar Oct 22 '24 15:10 andschub-ms

I'm also seeing this in 9.12.3, although the install still seems to work from what I can tell. Downgrading to 9.9.0 seems to resolve the issue for now, as I don't want these errors to cause problems in CI.

lukewhitehouse avatar Oct 29 '24 13:10 lukewhitehouse

This seems to be an issue with reporting only (so install actually succeeds but the warning about missing peers is not printed). Not sure how to fix it properly right now. I guess we could just skip the missing peer dependency warning in this case. It'll still be printed but not for all occurrences.

I'll make a PR.

zkochan avatar Nov 11 '24 01:11 zkochan

PR: https://github.com/pnpm/pnpm/pull/8745

zkochan avatar Nov 11 '24 01:11 zkochan

Thank you @zkochan!

VanTanev avatar Nov 11 '24 09:11 VanTanev

@zkochan a release with the fix would be appreciated. Thanks a lot!

sneridagh avatar Nov 11 '24 14:11 sneridagh

released

zkochan avatar Nov 14 '24 22:11 zkochan

released

Thank you for your support!

andschub-ms avatar Dec 03 '24 01:12 andschub-ms

I had to move "workspaces": [ "packages/*" ], from root package.json to pnpm-workspace.yaml
since I had WARN  The "workspaces" field in package.json is not supported by pnpm. Create a "pnpm-workspace.yaml" file instead.

that , in combination with downgrading to v9.9 , fixed the problem

spyrosbazios avatar Jan 09 '25 14:01 spyrosbazios

I fix it using pnpm approve-builds before building it , if it can help anybody

Zerostats avatar Mar 02 '25 21:03 Zerostats