Skip to content

[BUG] npm install hangs for ~2 minutes with optional dependencies in npm 10.9.0 #7900

Closed
@Guria

Description

@Guria

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 using npm 10.9.0, npm install hangs for approximately 2 minutes during the idealTree phase when package.json includes optional dependencies that return 404. The same package.json installs in ~5s with npm 10.8.2.

npm hangs during the idealTree phase for ~2 minutes
Eventually completes successfully
Time measurement: npm install takes 2+ minutes

Detailed logs and measurements can be found in repro repository

Expected Behavior

Quick failure/skip of optional dependencies
Similar to npm 10.8.2 behavior which completes in ~5s

Steps To Reproduce

Repository with minimal reproduction: https://github.com/Guria/npm10.9.0-hang-repro

Create package.json:

{
  "name": "npm-hang-repro",
  "version": "1.0.0",
  "description": "Reproduction for npm install hanging issue",
  "optionalDependencies": {
    "@nonexistent/package1": "^1.0.0",
    "@nonexistent/package2": "^1.0.0"
  },
  "dependencies": {
    "express": "^4.18.0"
  }
}

Steps to reproduce:

# Install npm 10.9.0
npm i -g npm@10.9.0

# Clean environment
npm cache clean --force
rm -rf node_modules package-lock.json

# Install with timing
time npm install --verbose --timing --loglevel silly

Environment

OS: Linux (Manjaro 6.10.13-3)
npm: 10.9.0
unaffected npm: 10.8.2
Node.js: both behaviors confirmed on v20.18.0 and v22.11.0

; node bin location = /home/aleksei_gurianov/.asdf/installs/nodejs/20.18.0/bin/node
; node version = v20.18.0
; npm local prefix = /home/aleksei_gurianov/ws
; npm version = 10.9.0
; cwd = /home/aleksei_gurianov/ws
; HOME = /home/aleksei_gurianov
; Run `npm config ls -l` to show all defaults.

Additional versions checks

Issue reproduces with npm@10.9.0 on all recent node versions:

  • Prev LTS: 20.18.0
  • Current LTS: 22.11.0
  • Latest: 23.2.0

No issue with npm@10.8.2 on all above versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions