Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:237:12)

in npm with 0 comment views: 1,136 times

错误描述

node 项目启动和 npm install 的时候报错:

npm 版本 5.8.0 或者更高的

在node_modules 文件夹生成一个 .staging 的文件夹,并且webstorm 上显示文件夹带有锁(权限问题)

解决权限问题可以参考: https://segmentfault.com/a/1190000009883516

但是这个问题不是权限导致的

错误信息

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at writeAfterEnd (_stream_writable.js:243:12)
    at PassThrough.Writable.write (_stream_writable.js:291:5)
    at PassThrough.Writable.end (_stream_writable.js:579:10)
    at ReadEntry.entry.on (/usr/local/lib/node_modules/npm/node_modules/libcipm/node_modules/pacote/lib/extract-stream.js:19:41)
    at ReadEntry.emit (events.js:187:15)
    at ReadEntry.emit (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:301:25)
    at ReadEntry.[maybeEmitEnd] (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:252:12)
    at ReadEntry.end (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:165:27)
    at Unpack.[consumeBody] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:210:13)
    at Unpack.[consumeChunkSub] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:391:40)
    at Unpack.[consumeChunk] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:362:30)
    at Unzip.(anonymous function).on.chunk (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:291:59)
    at Unzip.emit (events.js:182:13)
    at Unzip.emit (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:301:25)
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:102:17)
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib/index.js:284:29)
Emitted 'error' event at:
    at writeAfterEnd (_stream_writable.js:245:10)
    at PassThrough.Writable.write (_stream_writable.js:291:5)
    [... lines matching original stack trace ...]
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib/index.js:284:29)
events.js:167
      throw er; // Unhandled 'error' event
Error: write after end
    at MiniPass.write (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/minipass/index.js:81:13)
    at ReadEntry.entry.on (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/pacote/lib/extract-stream.js:30:21)
    at ReadEntry.emit (events.js:185:15)
    at ReadEntry.emit (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/node_modules/minipass/index.js:296:25)
    at ReadEntry.[maybeEmitEnd] (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/node_modules/minipass/index.js:249:12)
    at ReadEntry.end (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/node_modules/minipass/index.js:162:27)
    at Unpack.[consumeBody] (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/lib/parse.js:210:13)
    at Unpack.[consumeChunkSub] (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/lib/parse.js:391:40)
    at Unpack.[consumeChunk] (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/lib/parse.js:360:30)
    at Unzip.(anonymous function).on.chunk (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/lib/parse.js:291:59)
    at Unzip.emit (events.js:180:13)
    at Unzip.emit (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/node_modules/minipass/index.js:296:25)
    at Unzip.write (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/node_modules/minipass/index.js:99:17)
    at Unzip.write (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/node_modules/minizlib/index.js:284:29)
    at Unpack.write (/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/tar/lib/parse.js:307:19)
    at PassThrough.ondata (_stream_readable.js:651:20)
/Users/jpollak/.npm/_npx/99478/lib/node_modules/npmc/node_modules/minipass/index.js:81auth@0.9.7
      throw new Error('write after end')
      ^

解决问题

升级 npm 版本到 6.1

参考链接:https://github.com/npm/node-tar/issues/180
https://github.com/npm/npm/issues/19989

Responses