Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm ERR! premature close when using npm install

Getting [..................] / rollbackFailedOptional: verb npm-session 5d754927a47910d2 on installing from github.

Tried multiple things like cleaning cache, resetting proxy, etc but none of them work.

sudo npm install --save github:saarthak-jain/Blockchainbois-Voting

The log file attached is

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'install',
1 verbose cli   'saarthak-jain/Blockchainbois-Voting'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 5d754927a47910d2
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData error for github:saarthak-jain/Blockchainbois-Voting premature close
8 timing stage:rollbackFailedOptional Completed in 0ms
9 timing stage:runTopLevelLifecycles Completed in 7432ms
10 verbose stack Error: premature close
10 verbose stack     at PassThrough.onclose (/usr/local/lib/node_modules/npm/node_modules/end-of-stream/index.js:47:67)
10 verbose stack     at PassThrough.emit (events.js:201:15)
10 verbose stack     at emitCloseNT (internal/streams/destroy.js:68:8)
10 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:84:9)
11 verbose cwd /home/saarthak/FrontEnd
12 verbose Linux 4.18.0-18-generic
13 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "saarthak-jain/Blockchainbois-Voting"
14 verbose node v12.2.0
15 verbose npm  v6.9.0
16 error premature close
17 verbose exit [ 1, true ]
like image 711
Saarthak Avatar asked May 13 '19 18:05

Saarthak


4 Answers

I had the same situation when trying to install a package from Github with an invalid package.json file.

The file had an extra comma (,) and because of this I was faced with the same Error: premature close error.

like image 114
Ben Avatar answered Sep 21 '22 08:09

Ben


I'm going to "answer" this in case anyone gets here for the same reason I did.

npm install some/package

will fail with:

npm ERR! premature close

if "some/package" does not actually exist. Check to make sure you have the correct spelling on your package name.

For your entertainment, I was supposed to be using:

composer require some/package
like image 34
Jeff Martin Avatar answered Oct 06 '22 23:10

Jeff Martin


In my case, the package I was trying to install had a dependency on a Git repository that didn't have a package.json defined yet. My solution was to checkin/push the missing package.json.

like image 10
java-addict301 Avatar answered Oct 06 '22 22:10

java-addict301


After running yarn install I got this error:

error Error parsing JSON at "git://github.com/<xxx>.git/package.json", "Unexpected token } in JSON at position <yyy>".

Turns out I broke the package.json in <xxx>, fixing that solved the issue.

So:

  1. run yarn install, it may have a better log.
  2. package.json bugs can cause this.
like image 3
MikeL Avatar answered Oct 06 '22 23:10

MikeL