npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

"Premature close" error when fetching package from GitHub when `package.json` is invalid

What I Wanted to Do

Install/update a package from a remote Git repo.

What Happened Instead

This uninformative error:

$ npm upgrade ${some_package}
npm ERR! premature close

npm ERR! A complete log of this run can be found in:
npm ERR!     ${NPM_PREFIX}/.npm/_logs/2019-04-12T06_35_00_589Z-debug.log

Reproduction Steps

  1. Create a package with a syntactically invalid package.json and push it to a remote repo on GitHub. (It may repro on other platforms, but I’ve only tested GitHub.)
  2. Create a local module with a package.json that declares a devDependency on that package via a direct GitHub dependency. You can specify a #commit-ish, but it’s optional if the latest commit is syntactically invalid.
  3. Run npm install.


I would expect an error in this case, but an error telling me the package.json file contains invalid JSON. I would not expect an error like “premature close” that tells me it’s deceptively some sort of internal error.

Platform Info

$ npm --versions
<!-- paste output here -->
{ npm: '6.5.0',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.14.1',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '',
  zlib: '1.2.11' }
$ node -p process.platform
<!-- paste output here -->

This also happens if /tmp is on a full partition. A better error would be helpful.