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] npm install hangs for ~2 minutes with optional dependencies in npm 10.9.0 #7900

Closed
2 tasks done
Guria opened this issue Nov 9, 2024 · 14 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps

Comments

@Guria
Copy link

Guria commented Nov 9, 2024

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.

@Guria Guria added Bug thing that needs fixing Needs Triage needs review for next steps labels Nov 9, 2024
@Guria
Copy link
Author

Guria commented Nov 9, 2024

Just to clarify why using non-existing packages in optionalDependencies is a valid real-world scenario:

This pattern is commonly used when packages are optionally required based on environment. Some examples:

  1. Enterprise/Community edition split:

    // Only load enterprise features if the package is available
    try {
      enterpriseFeatures = require('@company/enterprise-features');
    } catch (e) {
      // Fall back to community features
    }
  2. Platform-specific dependencies:

    // Try to load platform-specific optimizations
    try {
      nativeBindings = require('@org/native-optimizations');
    } catch (e) {
      // Use JS fallback
    }
  3. Internal packages that are only available within corporate network/registry:

    // Load internal tooling if available
    try {
      internalTools = require('@internal/build-tools');
    } catch (e) {
      // Use public alternatives
    }

In all these cases, npm should gracefully skip unavailable optional dependencies rather than hanging. The 2-minute delay makes the development experience significantly worse, especially in CI/CD environments where multiple clean installs might be required.

@wickedest
Copy link

I think I am hitting this issue too. I'm running an install using gitlab-ci-local. It's using npm 10.9.0 (node:22-bookworm). For me, it never finishes (I killed it after 5m). For me, it hangs in idealTree. I ran it using npm 10.8.3 and placed both outputs side-by-side.
image

@Tofandel
Copy link

This is a duplicate of #4028

@Guria
Copy link
Author

Guria commented Nov 11, 2024

I am not sure it is exactly same.
In my case I have stable reproduction starting with 10.9.0, and no issue with 10.8.2.

Linked issue has been reported on earlier versions.

Looks more like #7814 and #7868.

@Tofandel
Copy link

Tofandel commented Nov 11, 2024

Which are also the same issue and on both it is either reported as starting in either 10.4.0 or 10.9.0, it is all an issue in the checkPlatform method, it has 2 different code paths which use it and maybe different resolution behaviors happen with different npm versions but at the core it's the same issue

Try to run your command with --libc="glibc" and it should fix it if you only hit the issue past 10.8.2, if not use --force instead

@paulrutter
Copy link

paulrutter commented Nov 15, 2024

I encountered a similar issue, while in my case npm install would never finish.
I narrowed it down to the isolated-vm dependency, which would never finish compiling (hanging on a gcc command randomly, viewed via --foreground-scripts).

The workaround that worked for me is setting --jobs 10 so compilation of native code doesn't take all CPU cores.
See https://github.com/nodejs/node-gyp?tab=readme-ov-file#command-options.

npm install --jobs 10 // or npm ci --jobs 10

It's not a pretty solution, and maybe it's not the same issue as described here, but it also hung upon npm install for an optional dependency in my case.

Node version: 22.11.0
NPM version: 10.9.0 (downgrading to 10.3.0 as suggested in this thread didn't help for me though)
Platform: Linux, Dockerized, Amazon Linux 2023 base image

VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2023"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="Amazon Linux 2023.6.20241010"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/"
DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/"
SUPPORT_URL="https://aws.amazon.com/premiumsupport/"
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
VENDOR_NAME="AWS"
VENDOR_URL="https://aws.amazon.com/"
SUPPORT_END="2028-03-15"

gcc --version
gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Hope this is helpful for others.

@kchindam-infy
Copy link

Based on testing on windows with node 23 and npm 10.9.0, I did not encounter the npm install hanging issue. Try using the node 23 to see if it resolves the issue.

@paulrutter
Copy link

Based on testing on windows with node 23 and npm 10.9.0, I did not encounter the npm install hanging issue. Try using the node 23 to see if it resolves the issue.

I'm keen on using LTS versions only, so even if that solves the issue, it's not a good solution until it would land in node 22 as well.

@Guria
Copy link
Author

Guria commented Nov 15, 2024

@paulrutter It wasn't suggestion to use non LTS version, but just to test if your case is still reproduced on this version in order to help triage

@paulrutter
Copy link

@paulrutter It wasn't suggestion to use non LTS version, but just to test if your case is still reproduced on this version in order to help triage

Sorry, i misunderstood. I can try that next week.

@Tofandel
Copy link

@paulrutter your issue is the only one that seems different from this issue and all the other linked issue, especially given the fact you still had it on 10.3.0

@paulrutter
Copy link

paulrutter commented Nov 15, 2024

@paulrutter your issue is the only one that seems different from this issue and all the other linked issue, especially given the fact you still had it on 10.3.0

Yes, true. I suspect it's an issue with that specific dependency, hence i also created an issue there.

@Tofandel
Copy link

Tofandel commented Nov 22, 2024

@Guria This should be fixed in npm 10.9.1, could you try that and confirm?

@Guria
Copy link
Author

Guria commented Nov 23, 2024

Thanks, I've checked and can confirm that my case is solved with 10.9.1

@Guria Guria closed this as completed Nov 23, 2024
StorytellerCZ added a commit to StorytellerCZ/meteor that referenced this issue Dec 11, 2024
This is to include fix for this annoyance: npm/cli#7900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps
Projects
None yet
Development

No branches or pull requests

5 participants