Open Guria opened 1 week ago
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:
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
}
Platform-specific dependencies:
// Try to load platform-specific optimizations
try {
nativeBindings = require('@org/native-optimizations');
} catch (e) {
// Use JS fallback
}
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.
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.
This is a duplicate of https://github.com/npm/cli/issues/4028
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.
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
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.
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.
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.
@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 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.
@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 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.
@Guria This should be fixed in npm 10.9.1, could you try that and confirm?
Is there an existing issue for this?
This issue exists in the latest npm version
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:
Steps to reproduce:
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
Additional versions checks
Issue reproduces with npm@10.9.0 on all recent node versions:
No issue with npm@10.8.2 on all above versions.