cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] ERR! this.idealTree.children.get is not a function

Open maksimr opened this issue 2 years ago • 9 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

Get an error when try to install dependencies for specific workspace using "linked" strategy

mk bar \
  && pushd bar \
  && npm init -y \
  && npm init -y -w foo-1 \
  && npm install --install-strategy=linked -w foo-1

Expected Behavior

Install dependencies only for passed workspace using "linked" strategy

Steps To Reproduce

Darwin 23.2.0
node v20.9.0
npm  v10.1.0
  1. Run
mk /tmp/bar \
  && pushd /tmp/bar \
  && npm init -y \
  && npm init -y -w foo-1 \
  && npm install --install-strategy=linked -w foo-1
  1. See error:
npm ERR! this.idealTree.children.get is not a function

Environment

  • npm: v10.1.0
  • Node.js: v20.9.0
  • OS Name: Darwin 23.2.0
  • System Model Name: MacBook Air
  • npm config:
; node bin location = /Users/maksimrv/.nvm/versions/node/v20.9.0/bin/node
; node version = v20.9.0
; npm local prefix = /private/tmp/bar
; npm version = 10.1.0
; cwd = /private/tmp/bar
; HOME = /Users/maksimrv
; Run `npm config ls -l` to show all defaults.

maksimr avatar Nov 27 '23 20:11 maksimr

Just proof of concept. All works fine if modify this line

image

this.idealTree.children in case of "linked" strategy contains Array instead of Set

maksimr avatar Nov 27 '23 21:11 maksimr

Seems like perhaps the bug, then, is that it doesn't always contain a Set. Where is it created as an Array? perhaps that can be changed instead.

ljharb avatar Nov 27 '23 21:11 ljharb

Where is it created as an Array?

It replaced on Array here -> isolated-reifier

maksimr avatar Nov 27 '23 22:11 maksimr

and would wrapping that array in new Set() fix the problem?

ljharb avatar Nov 27 '23 22:11 ljharb

and would wrapping that array in new Set() fix the problem?

Yah, if add something like this:

    root.children = new Map(root.children.map(c => [c.name, c]))

fixes error but looks like it doesn't work correctly because:

  1. Install all dependencies
  2. Does not link some modules

: (

maksimr avatar Nov 27 '23 22:11 maksimr

not new Map, new Set - since you said it's a Set in the other code paths.

There may be other places that assume it's an array that also need updating, ofc.

ljharb avatar Nov 27 '23 22:11 ljharb

not new Map, new Set - since you said it's a Set in the other code paths.

There may be other places that assume it's an array that also need updating, ofc.

Actually, there is a Map not a Set. I'm not sure why I wrote Set

const ideal = this.idealTree.children.get(ws)

maksimr avatar Nov 27 '23 22:11 maksimr

Hi, any update on this issue?

Juknum avatar Jun 17 '24 13:06 Juknum

Can't have two version of a package installed with npm, can't fix it due to this bug :/

kristojorg avatar Jan 08 '25 18:01 kristojorg