Npm install hangs intermittently

I’m running an npm step to install missing packages, but sometimes it will just hang at this point indefinitely. Other times it will complete in under 2 mins, or it will complete after some other time (we’ve seen it complete after 10 mins and after 40 mins). There doesn’t seem to be any obvious pattern as to when it will hang or for how long it will hang (the longest we’ve gotten is just over an hour before aborting the build)

Running the CI build locally doesn’t seem to run into any issues like this either. Has anyone else seen this or have any idea what could be causing it?

Hi @james_furlong , can you share a build url with support access enabled so that we can take a quick look?
Best regards,
Silvercast

Hi @silvercast.nguyen yeah of course:
Bitrise - Mobile Continuous Integration and Delivery - iOS & Android Build Automation - This was a ‘successful’ build regarding the npm install step (although it took 11m to complete and failed at another step)
Bitrise - Mobile Continuous Integration and Delivery - iOS & Android Build Automation - This is the build after the one above where is hung at the npm install step for an hour before being aborted

Looks like you have some customer npm scripts > milanote@3.[REDACTED].77 postinstall which triggers > ./scripts/docker-npm-install.sh . Do you notice the same issue on more powerful Linux machines Pricing and Plans for Mobile DevOps - Bitrise ?
Best regards,
Silvercast

Sounds like a classic npm flake in CI instead of a code problem. Network timeouts hitting the npm registry or a low entropy/randomness issue in the CI environment can cause inconsistent hangs that slow down package resolution. Here are some things that can help: Use .nvmrc and package-lock to lock down the versions of node and npm you use. For builds that can be repeated, try using npm ci instead of npm install. If you can, turn on a local cache of packages in your CI runner. Verbose logging (npm install --verbose) can also sumtimes show which package is stuck. Most of the time, it’s one of the optional dependencies that fails without saying anything.