Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
fatso83 opened this issue Oct 12, 2022 · 4 comments
Open
2 tasks done
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 8.x work is associated with a specific npm 8 release

Comments

@fatso83
Copy link

fatso83 commented Oct 12, 2022

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.
@fatso83 fatso83 added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Oct 12, 2022
@fritzy fritzy added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Oct 18, 2022
@fritzy
Copy link
Contributor

fritzy commented Oct 18, 2022

Theoretically, links shouldn't be an issue. This is worth fixing.

@trusktr
Copy link

trusktr commented Oct 24, 2023

I'm also having this issue. In a workspace I have to run npm run version --no-workspaces ... to avoid the error. Other workspaces outside of the workspace where I'm running npm version are linked together using yarn install.

I also have a similar problem when not using --no-workspaces with this error for npm install:

trusktr added a commit to lume/cli that referenced this issue Nov 5, 2023
…rettier'

* remove-global-builds-switch-to-web-test-runner-update-prettier: (29 commits)
  feat: fallback to loading jest globals in test-runner from the hoisted node_modules location if it is not located in lume/cli's node_modules
  BREAKING: add a check to ensure that the repo is not modified before versioning during release. Repo author should be sure to commit build outputs, or fix the build so no changes happen during build that are not tracked.
  undo testing in firefox and safari for now, some lume code needs fixing
  BREAKING: besides Chromium, also run tests in Firefox and Safari in CI. Migration: If you didn't test those browsers before, you might have to update any code that is not compatible. Alternatively, make sure there is no CI env var set and it will test in Chrome only.
  update test-runner port range to avoid ports denylisted by Chrome
  install web test-runner's playwright launcher, and use that to run tests in Chrome in CI
  run tests on a random port to avoid collisions when running tests in parallel for multiple projects at the same time
  BREAKING: migrate from Karma to `@web/test-runner`. This removed a lot of dependencies (namely Webpack needed for the Karma setup), greatly reduces maintenance burden, speeds tests up, provides a much simpler and better test development and debugging experience with minimal configuration compared to with Karma, and ensures longevity of test code by ensuring that they run as standard JavaScript modules. 🎉 The `webpackConfigs` and `testSpecFormat` options for `lume.config.cjs` have been removed. Migration: Delete any webpack configs, all code should be vanilla JavaScript (ES) modules. There is only one test spec format now (Mocha `describe()`/`it()` and Jest `expect()`). Test syntax is mostly the same, and most tests will remain as-is. A few things need to be changed from Jasmine's `expect()` API to Jest's very similar `expect()` API. For example, `expect(true).toBeTrue()` needs to be changed to `expect(true).toBe(true)`. `jasmine.*` API is removed, f.e. `jasmine.createSpy` can be replaced with `sinon.spy()`. Try running tests, see what broke, then look up the way to do it with Jest or with Sinon, etc. Also tests are executed as vanilla ES Modules in a browser, and an `importMap` field will need to be defined in `lume.config.js` to handle bare specifiers (f.e. the `foo` in `import something from 'foo'`). Only ES Modules are supported, so if any libraries are CommonJS, those will not work and alternatives will be needed. The CLI can be forked though, and `@web/test-runner`'s config can be expanded to use its built-in `esbuild` plugin, along with Rollup plugins for any non-vanilla-ESM use cases.
  BREAKING: instead of trying to stash changes and continuing with versioning and publishing, exit non-zero if the working directory is dirty. Migration: clear your git repo of changes, then try again.
  update version scripts to avoid an issue with workspaces and linked dependencies (npm/cli#5687, npm/cli#4787)
  BREAKING: remove the global build feature, from now on we output and publish only JS modules for simplicity. Migration: @lume/cli will no longer output global.js files for use with non-module script tags, instead any code depending on your @lume/cli-managed package should use `import` syntax to import your package.
  port karma bash script to Node so it works in Windows too
  ensure line endings match with the rest of our tooling (all work in LF)
  ensure that we also get tsc, babel, and prettier bins with Node module lookup to avoid relying on PATH (Yarn and NPM set PATH differently, see Yarn issue 5800)
  update exec calls to find binaries using node_module resolution instead of relying on PATH to prevent cross-platform issues with Windows, and make the noFailOnError option use || echo '' instead of || true for cross-platform support
  prevent duplicate solid-js libs. Its ok to hard code this one case, because solid-js is a key dependency of lume
  Avoid error with fs.mkdir if dir already exists. Why is it so difficult?
  ensure dist/ is created before we copy assets to hopefully solve a problem with this in Windows CI (https://github.com/lume/lume/actions/runs/6519881972/job/17706893670)
  update prettier to 3.0.3
  infra: add .gitattributes with rules to enforce that code is checked out with LF line endings only, which prevents Prettier from failing in Windows
  ...
@trusktr
Copy link

trusktr commented Nov 22, 2023

@fritzy this isn't only about links. I have no links in node_modules of the project with this error, but the project is simply a workspace (a git submodule in a super repo).

@SimenB
Copy link
Contributor

SimenB commented Jan 5, 2024

getting a similar error trying to run npm dedupe in https://github.com/open-telemetry/opentelemetry-js-contrib - npm install completes just fine.

6004 verbose stack TypeError: Cannot read properties of null (reading 'isDescendantOf')
6004 verbose stack     at #resolveLinks (/Users/simen/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1414:37)
6004 verbose stack     at #buildDepStep (/Users/simen/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:783:32)
6004 verbose stack     at #buildDepStep (/Users/simen/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1035:30)
6004 verbose stack     at async Arborist.buildIdealTree (/Users/simen/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:196:7)
6004 verbose stack     at async Promise.all (index 1)
6004 verbose stack     at async Arborist.reify (/Users/simen/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:159:5)
6004 verbose stack     at async Dedupe.exec (/Users/simen/.nvm/versions/node/v20.10.0/lib/node_modules/npm/lib/commands/dedupe.js:47:5)
6004 verbose stack     at async module.exports (/Users/simen/.nvm/versions/node/v20.10.0/lib/node_modules/npm/lib/cli-entry.js:61:5)
6005 verbose cwd /Users/simen/repos/opentelemetry-js-contrib
6006 verbose Darwin 23.2.0
6007 verbose node v20.10.0
6008 verbose npm  v10.2.5
6009 error Cannot read properties of null (reading 'isDescendantOf')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

4 participants