premature close during npm install

(Ken Leidal) #1

What I Wanted to Do

I wanted to install a repository from github: npm install git+https://github.com/kkleidal/npm-bugreport.git.

What Happened Instead

npm ERR! premature close

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/kkleidal/.npm/_logs/2019-04-04T17_12_41_456Z-debug.log

Reproduction Steps

In Docker:

This fails (I believe because of the node_modules directory with symlink examples/simple/node_modules/bugreport)

$ docker run -it --rm node:10.15.3-alpine sh -c "apk add git && npm install git+https://github.com/kkleidal/npm-bugreport.git"
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/7) Installing ca-certificates (20190108-r0)
(2/7) Installing nghttp2-libs (1.35.1-r0)
(3/7) Installing libssh2 (1.8.2-r0)
(4/7) Installing libcurl (7.64.0-r1)
(5/7) Installing expat (2.2.6-r0)
(6/7) Installing pcre2 (10.32-r1)
(7/7) Installing git (2.20.1-r0)
Executing busybox-1.29.3-r10.trigger
Executing ca-certificates-20190108-r0.trigger
OK: 22 MiB in 23 packages
npm ERR! premature close

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-04-04T17_20_48_846Z-debug.log

With .npmignore of the offending directory (examples/simple/node_modules):

$ docker run -it --rm node:10.15.3-alpine sh -c "apk add git && npm install git+https://github.com/kkleidal/npm-bugreport.git#good"
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/7) Installing ca-certificates (20190108-r0)
(2/7) Installing nghttp2-libs (1.35.1-r0)
(3/7) Installing libssh2 (1.8.2-r0)
(4/7) Installing libcurl (7.64.0-r1)
(5/7) Installing expat (2.2.6-r0)
(6/7) Installing pcre2 (10.32-r1)
(7/7) Installing git (2.20.1-r0)
Executing busybox-1.29.3-r10.trigger
Executing ca-certificates-20190108-r0.trigger
OK: 22 MiB in 23 packages
npm WARN saveError ENOENT: no such file or directory, open '/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data
npm WARN !invalid#1 No license field.

+ posh-errors@0.0.1
added 1 package from 1 contributor and audited 1 package in 1.135s
found 0 vulnerabilities

Details

I think the bug is due to the symlink I have to the root of the project in the example’s node_modules directory. I understand that this might be a niche feature that npm doesn’t support, but there should be a more helpful error than “premature exit” because I had to spend a long time debugging to find it. Also, it works fine with yarn.

Here is my npm debug log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/src/node-v10.15.0-linux-x64/bin/node',
1 verbose cli   '/usr/local/src/node-v10.15.0-linux-x64/bin/npm',
1 verbose cli   'install',
1 verbose cli   'git+https://github.com/kkleidal/npm-bugreport.git' ]
2 info using npm@6.4.1
3 info using node@v10.15.0
4 verbose npm-session 16c4acf107561cf1
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 info lifecycle posh-errors@0.0.1~prepack: posh-errors@0.0.1
8 silly fetchPackageMetaData error for git+https://github.com/kkleidal/npm-bugreport.git premature close
9 timing stage:rollbackFailedOptional Completed in 1ms
10 timing stage:runTopLevelLifecycles Completed in 2105ms
11 verbose stack Error: premature close
11 verbose stack     at PassThrough.onclose (/usr/local/src/node-v10.15.0-linux-x64/lib/node_modules/npm/node_modules/end-of-stream/index.js:47:67)
11 verbose stack     at PassThrough.emit (events.js:187:15)
11 verbose stack     at emitCloseNT (internal/streams/destroy.js:59:8)
11 verbose stack     at process._tickCallback (internal/process/next_tick.js:63:19)
12 verbose cwd /home/kkleidal/Projects/npm/sandbox
13 verbose Linux 4.15.0-46-generic
14 verbose argv "/usr/local/src/node-v10.15.0-linux-x64/bin/node" "/usr/local/src/node-v10.15.0-linux-x64/bin/npm" "install" "git+https://github.com/kkleidal/npm-bugreport.git"
15 verbose node v10.15.0
16 verbose npm  v6.4.1
17 error premature close
18 verbose exit [ 1, true ]

Platform Info

$ npm --versions
{ npm: '6.4.1',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.0',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.45',
  zlib: '1.2.11' }
$ node -p process.platform
linux
0 Likes