help icon indicating copy to clipboard operation
help copied to clipboard

Npm install freezes for couple of minutes

Open sirdawidd opened this issue 3 years ago • 2 comments

Version

17

Platform

docker node:17-alpine

Subsystem

No response

What steps will reproduce the bug?

Maybe someone faced same issue with NodeJS. It doesn't matter which version but what is important is that I'm trying to build docker container and resources (npm packages are hosted in Azure).

I'm trying to build sample container

FROM node:16-alpine as build
ENV CI=true
COPY package*.json /app/
WORKDIR /app
npm ci
# ^ this step makes that after packages are restored , everything freezes for 4-6 mins then it continue, all works fine the problem is: what takes 4 minutes? In verbose mode I don't see anything is happening at this time (after packages are restored). Increasing memory, does not help.

The output from restoring packages is simple

added 1463 packages in 1m

184 packages are looking for funding
  run `npm fund` for details
npm notice 
npm notice New minor version of npm available! 8.3.1 -> 8.5.3
npm notice Changelog: <[https://github.com/npm/cli/***s/tag/v8.5.3>](https://github.com/npm/cli/***s/tag/v8.5.3%3E)
npm notice Run `npm install -g [email protected]` to update!
npm notice

And after restore it freezes, for few minutes. Does node is trying to sync node_modules or what exactly is happening after restore?

Even the restoring takes 1minute whole step is 5-7mins long.

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

Restore npm packages without downtime

Additional information

No response

sirdawidd avatar Mar 08 '22 09:03 sirdawidd

It doesn't actually freeze in this case, it's actually processing everything that has to be installed, built, compiled and all of that, and of course the ideal tree, as you're running the clean-install sub-command (npm clean-install | npm ci) to do a clean install of all the NPM packages/libraries installed. Some NPM packages/libraries that you may want to install can have an additional step to build binaries or their source files, such as C++ addons written with Node-API (N-API) and compiled with build tools such as node-gyp which can take quite a while considering the fact that they're compiling C++ source files and building to be usable*.

An example of this can be replicated by installing the sodium encryption library which includes C++ addons to build using node-gyp, which takes a while:

$ npm i sodium

Some NPM packages/libraries can also include huge codebases or many sub-modules which can also cause it to be processed for a few minutes or more, although it's unlikely.

* The build process of C++ files are also explained here.

VoltrexKeyva avatar Mar 14 '22 09:03 VoltrexKeyva

@sirdawidd - is this resolved?

gireeshpunathil avatar Jun 21 '22 14:06 gireeshpunathil

closing as inactive

gireeshpunathil avatar Aug 02 '23 02:08 gireeshpunathil