Docker-node: Last alpine image breaks npm install with git+ssh

Created on 23 Oct 2020  路  6Comments  路  Source: nodejs/docker-node

It looks like NPMv7 npm install wants to use bash, which is not present in alpine image. NPMv6 works fine on lts-alpine.
DIGEST: sha256:97204ef250fa90f8177084ef6d7641ede6d48c4c8acfb30faf3580bee5c59c0b

Is it NPM problem or with some settings connected with latest image?

Log:

npm WARN tarball tarball data for XXX@git+ssh://[email protected]/XXX/XXX.git#hash (null) seems to be corrupted. Trying again.
npm WARN tarball tarball data for XXX@git+ssh://[email protected]/XXX/XXX.git#hash (null) seems to be corrupted. Trying again.
npm notice 
npm notice New patch version of npm available! 7.0.2 -> 7.0.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
npm notice Run `npm install -g [email protected]` to update!
npm notice 
npm ERR! code ENOENT
npm ERR! syscall spawn bash
npm ERR! path bash
npm ERR! errno -2
npm ERR! enoent spawn bash ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 
question

Most helpful comment

Default shell was fixed in NPM and included in the 15.1.0 images

All 6 comments

I don't know what package you're trying to install - I'm assuming it is due to some pre-built binary not being available, so it attempts to build from source, which requires bash. Hard to tell without more details, however.

I don't think it's a bug in this image or in npm. I might be wrong though. You should take a look at the logfile after the failure.

It looks like NPMv7 issue:
https://github.com/npm/cli/issues/2008
https://github.com/npm/cli/issues/2022
So this issue can be closed.

It turns out that NPMv7 respects shell config option and NPMv6 does not (in this case).

NPMv6:

damian_koper@X:~/Desktop/npm-test $ docker run -it node:lts-alpine sh
/ # npm -v
6.14.8
/ # npm config ls -l | grep shell
script-shell = null
shell = "bash"
/ # apk add git
OK: 23 MiB in 22 packages
/ # npm i github:damiankoper/piw.git # random repo
# WORKS

NPMv7:

damian_koper@X:~/Desktop/npm-test $ docker run -it node:alpine sh
/ # npm -v
7.0.3
/ # npm config ls -l | grep shell
script-shell = null 
shell = "bash" 
/ # apk add git
OK: 23 MiB in 22 packages
/ # npm i github:damiankoper/piw.git # random repo
npm ERR! code ENOENT
npm ERR! syscall spawn bash
npm ERR! path bash
npm ERR! errno -2
npm ERR! enoent spawn bash ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

Solution for NPMv7:

/app # npm config set shell sh # Should this be added to alpine Dockerfile with NPMv7?
validBefore? true
/ # npm i github:damiankoper/piw.git # random repo
WORKS

so npm defaults to bash? They should probably default to. sh as that's more portable. We can probably set that config option, tho.

I had the same issue (installing package from git) and adding the following line in my Dockerfile fixes the issue. Thanks @damiankoper

npm config set shell sh

_Edit: answer to the next comment, yes v15.1.0 solve the issue ^^_

Default shell was fixed in NPM and included in the 15.1.0 images

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eyaylagul picture eyaylagul  路  3Comments

sam-github picture sam-github  路  4Comments

retrohacker picture retrohacker  路  3Comments

polys picture polys  路  3Comments

jtcmedia picture jtcmedia  路  5Comments