Skip to content

[BUG] linked strategy: npm query ':root > *' returns incorrect results #9093

@manzoorwanijk

Description

@manzoorwanijk

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

npm query ':root > *' --install-strategy=linked returns incorrect results:

  1. Transitive dependencies appear as direct children of root (e.g. abbrev which is only a dependency of nopt, not a root dependency).
  2. Bare store directory nodes without a name appear in results (e.g. node_modules/.store/nopt@7.2.1-... with no name field).
  3. The total number of results is higher than the actual number of direct dependencies.

This affects both workspace and non-workspace projects. With the hoisted strategy, :root > * correctly returns only direct dependencies.

Expected Behavior

npm query ':root > *' should return only the direct dependencies declared in package.json. For the example below with nopt, ini, and semver as direct deps, it should return exactly 3 entries.

Steps To Reproduce

  1. Create a project:
mkdir test-query && cd test-query

cat > package.json << 'EOF'
{
  "name": "test-query",
  "version": "1.0.0",
  "dependencies": { "nopt": "^7.0.0", "ini": "^4.0.0" },
  "devDependencies": { "semver": "^7.0.0" }
}
EOF
  1. Install and query:
npm install --install-strategy=linked
npm query ':root > *' --install-strategy=linked
  1. Returns 5 entries instead of 3. Extracting name and location:
name=abbrev, location=node_modules/.store/abbrev@2.0.0-.../node_modules/abbrev
name=ini, location=node_modules/.store/ini@4.1.3-.../node_modules/ini
name=?, location=node_modules/.store/nopt@7.2.1-...
name=semver, location=node_modules/.store/semver@7.7.4-.../node_modules/semver
name=nopt, location=node_modules/.store/nopt@7.2.1-.../node_modules/nopt
  • abbrev is a transitive dep of nopt, not a root dep — should not appear.
  • The entry at node_modules/.store/nopt@7.2.1-... has no name — this is a bare store directory node leaking into results.

Environment

  • npm: 11.11.0
  • Node.js: v22.20.0
  • OS Name: macOS (Darwin 25.3.0)
  • System Model Name: Mac
  • npm config:
install-strategy=linked

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions