cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] When using Docker image, installing package globally is hanging

Open cmerat opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

When installing a package globally, the installation "hangs" after "fetch/packumentCache" steps for minutes before proceeding and completing with a bunch of "placeDep" steps. This behavior started happening approximately two months ago and has continued since. This is making building the container images for my app very slow (5+ mins). npm-install.log

Expected Behavior

The installation should not hang or, at the very least, give me feedback on what is taking so long.

Steps To Reproduce

  1. docker run -it --rm --entrypoint /bin/sh node:20-alpine
  2. npm i -g --verbose vite

Environment

  • npm: 10.8.2
  • Node.js: 20.12.2
  • OS Name: Alping Linux
  • System Model Name: Docker Desktop
  • npm config:
; node bin location = /usr/local/bin/node
; node version = v20.12.2
; npm local prefix = /
; npm version = 10.8.2
; cwd = /
; HOME = /root
; Run `npm config ls -l` to show all defaults.

cmerat avatar Jul 24 '24 22:07 cmerat

@cmerat The installation is not completing or it's taking time ? Based on your logs it looks like installation was complete, also time taken by installation depends on various factors like network speed and computing resources. you can use log level silly for even more logs. I did try the the steps in docker node alpine and it worked fine.

milaninfy avatar Jul 30 '24 14:07 milaninfy

@milaninfy it eventually completes, usually taking between 5 and 10 minutes. A few months ago, it would complete in seconds. Not sure what is going on and the logs aren't verbose enough (even with silly level logging) to give me enough information. Would really love the log to have timestamps, too. Would really help with figuring out where it's hanging.

I could be completely wrong, but from verbose logging I see in the shell, it's somewhere between lines 210 and 256 since the delay is between those two verbose lines being output to console. Lines here are file number lines, not the logging index at the start of each line.

cmerat avatar Jul 30 '24 18:07 cmerat

There is a problem with npm install since node 20 #https://github.com/nodejs/docker-node/issues/1946 It only affects images that use musl as c lib, alpine is among them. The root cause seems to come from qemu which is used by docker https://gitlab.com/qemu-project/qemu/-/issues/1729. The issue is stalling at the qemu project, Apparently, there was a change in npm with node 20 that hits the qemu bug.

fuhlich avatar Aug 27 '24 05:08 fuhlich

Could you please try with latest npm 10.9.1 ? Issue might have been fixed (via https://github.com/npm/npm-install-checks/pull/120)

milaninfy avatar Nov 22 '24 09:11 milaninfy

Confirmed that it appears to be have been fixed with npm 10.9.1. Now takes a few seconds rather than minutes.

cmerat avatar Nov 22 '24 12:11 cmerat