Skip to content

[BUG] Running npm i fails with Cannot read properties of null (reading 'isDescendantOf') #5687

Open
@fatso83

Description

@fatso83

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When installing a project using PNPM first and then subsequently using standard npm to install it, the install process borks after a long time with:

npm ERR! Cannot read properties of null (reading 'isDescendantOf')

Looking at the generated debug log one can see a null pointer being mentioned:

``` 9918 timing idealTree:node_modules/.pnpm/node_modules/eslint/node_modules/table/node_modules/strip-ansi Completed in 1ms 9919 timing idealTree:node_modules/.pnpm/node_modules/eslint/node_modules/table/node_modules/ansi-regex Completed in 0ms 9920 timing idealTree:node_modules/.pnpm/node_modules/fast-glob/node_modules/glob-parent/node_modules/is-glob Completed in 0ms 9921 timing idealTree Completed in 14547ms 9922 timing command:i Completed in 14573ms 9923 verbose stack TypeError: Cannot read properties of null (reading 'isDescendantOf') 9923 verbose stack at [resolveLinks] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1419:37) 9923 verbose stack at [buildDepStep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:792:33) 9923 verbose stack at [buildDepStep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1047:31) 9924 verbose cwd /home/carlerik/code/example-encrypt-properties 9925 verbose Linux 5.15.0-47-generic 9926 verbose node v18.10.0 9927 verbose npm v8.19.2 9928 error Cannot read properties of null (reading 'isDescendantOf') 9929 verbose exit 1 9930 timing npm Completed in 14748ms 9931 verbose unfinished npm timer reify 1665582899091 9932 verbose unfinished npm timer reify:loadTrees 1665582899109 9933 verbose unfinished npm timer idealTree:buildDeps 1665582899389 9934 verbose unfinished npm timer idealTree:node_modules/.pnpm/[email protected]/node_modules/yargs 1665582906713 9935 verbose code 1 9936 error A complete log of this run can be found in: 9936 error /home/carlerik/.npm/_logs/2022-10-12T13_54_58_915Z-debug-0.log ```

Adding a console.log("link.target is null!", link) just before it fails shows this:
image

This points at one of the PNPM installed files being an issue of some sort. Maybe due to the symlinks created?
image

Expected Behavior

I would expect that NPM would go about its business and handle the situation where PNPM previously has stepped all over its turf gracefully 😄

It took some attempts (actually writing this) to discover that wiping with rm -r node_modules would fix the issue, so maybe one could add some heuristics to detect weird symlinks where there should not be and just delete the directory before re-installing? That would be very user friendly, at least.

Steps To Reproduce

  1. hub clone fatso83/example-encrypt-properties (clone this repo)
  2. cd example-encrypt-properties && pnpm i && npm i
  3. Observe an error: npm ERR! Cannot read properties of null (reading 'isDescendantOf')

Environment

  • npm: 7.12.0 (also tested on v6)
  • Node.js: 18.10.0 (latest, also tested on v16)
  • OS Name: Ubuntu 22.04.1 LTS
  • System Model Name: ?
  • npm config:
; "user" config from /home/carlerik/.npmrc

//registry.npmjs.org/:_authToken = (protected) 
flex-sdk:npm_cmd_ran = "install" 

; node bin location = /usr/local/bin/node
; node version = v18.10.0
; npm local prefix = /home/carlerik/code/nimble
; npm version = 8.19.2
; cwd = /home/carlerik/code/nimble
; HOME = /home/carlerik
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issueRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions