npm ERR! code ERR_STREAM_WRITE_AFTER_END

npm ERR! code ERR_STREAM_WRITE_AFTER_END

NPM errorToday I have encountered a problem with NPM. When I tried to install a new package, it returned me npm ERR! code ERR_STREAM_WRITE_AFTER_END. I would like to share the details and the solution for those of you who will see the same error.

Problem

I tried to install copy-webpack-plugin using NPM and I have got ERR_STREAM_WRITE_AFTER_END error.

C:\Git\myproject>npm install --save-dev copy-webpack-plugin
npm ERR! code ERR_STREAM_WRITE_AFTER_END
npm ERR! write after end
npm ERR! code ERR_STREAM_WRITE_AFTER_END
npm ERR! write after end
npm ERR! code ERR_STREAM_WRITE_AFTER_END
npm ERR! write after end

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\dba\AppData\Roaming\npm-cache\_logs\2018-08-01T13_13_37_418Z-debug.log

I have checked the log file on the location from the message.

1243 verbose stack Error [ERR_STREAM_WRITE_AFTER_END]: write after end
1243 verbose stack at writeAfterEnd (_stream_writable.js:237:12)
1243 verbose stack at PassThrough.Writable.write (_stream_writable.js:289:5)
1243 verbose stack at PassThrough.Writable.end (_stream_writable.js:565:10)
1243 verbose stack at ReadEntry.entry.on (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\lib\extract-stream.js:19:41)
1243 verbose stack at ReadEntry.emit (events.js:164:20)
1243 verbose stack at ReadEntry.emit (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\node_modules\minipass\index.js:296:25)
1243 verbose stack at ReadEntry.[maybeEmitEnd] (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\node_modules\minipass\index.js:249:12)
1243 verbose stack at ReadEntry.end (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\node_modules\minipass\index.js:162:27)
1243 verbose stack at Unpack.[consumeBody] (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\lib\parse.js:210:13)
1243 verbose stack at Unpack.[consumeChunkSub] (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\lib\parse.js:391:40)
1243 verbose stack at Unpack.[consumeChunk] (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\lib\parse.js:362:30)
1243 verbose stack at Unzip.(anonymous function).on.chunk (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\lib\parse.js:291:59)
1243 verbose stack at Unzip.emit (events.js:159:13)
1243 verbose stack at Unzip.emit (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\node_modules\minipass\index.js:296:25)
1243 verbose stack at Unzip.write (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\node_modules\minipass\index.js:99:17)
1243 verbose stack at Unzip.write (C:\Users\dba\AppData\Roaming\npm\node_modules\npm\node_modules\tar\node_modules\minizlib\index.js:284:29)
1244 verbose cwd D:\Git\Reservations\reservations-salon
1245 verbose Windows_NT 10.0.17134
1246 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\dba\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save-dev" "copy-webpack-plugin"
1247 verbose node v9.3.0
1248 verbose npm v5.10.0
1249 error code ERR_STREAM_WRITE_AFTER_END
1250 error write after end
1251 verbose exit [ 1, true ]

Do not miss valuable content. You will receive a monthly summary email. You can unsubscribe anytime.

Solution

I have checked this error on the internet and I found that a similar issue was reported to NPM https://github.com/npm/npm/issues/19989 and solved in NPM 6.1.0. I checked which version I have:

D:\Git\myproject>npm -v
5.10.0

It seemed that an upgrade should solve the case.

Before I did that, I also checked the latest Node.js version available which was 8.11.3 that included NPM 5.6.0 (even older than I already had). It was not sufficient so I upgraded NPM only:

D:\Git\myproject>npm install npm@latest -g
C:\Users\dba\AppData\Roaming\npm\npx -> C:\Users\dba\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
C:\Users\dba\AppData\Roaming\npm\npm -> C:\Users\dba\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
+ npm@6.2.0
added 271 packages from 147 contributors, removed 439 packages and updated 21 packages in 128.695s

D:\Git\myproject>npm -v
6.2.0

Then installing copy-webpack-plugin was successful.

 

Some time ago, I also got a different error which required upgrading NPM - npm ERR! peerinvalid.

If you like what I do, consider buying me a coffee :)

Buy me a coffeeBuy me a coffee