npm Community Forum (Archive)

The npm community forum has been discontinued.

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

npm-lifecycle produces "Possible EventEmitter memory leak detected" when running multiple dependencies' post-install scripts

Thanks in advance for any triage help :sparkling_heart:

What I Wanted to Do

Run a variety of my dependencies post-install scripts without unexpected warnings or errors

What Happened Instead

I received a “(node:17211) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added.” during npm install.

Note: AFAICT npm install still completed fine and installed all deps as normal.

Reproduction Steps

  1. Create a project whose dependencies include at least 11 packages who run post-install scripts
  2. Clear out the node_modules directory for that project
  3. run npm install


I don’t have a ton of insight into this to be honest, its something we just started encountering with our (private) repo at work after refactoring some of our dependencies. I saw an open issue ( where someone identified a possible cause as the removal of a function from the wrong process signal. I admittedly don’t know enough about that to feel confident to make a PR, so I wanted to bring it up here to possibly triage. I’m happy to make a PR for that change if someone thinks it’s the right one!

I guess this isn’t a really big issue, its only a warning, but we’ve already lost a day or two from several devs here because nobody knew what that warning meant, whether it was our code or someone else’s code that caused it, and how to address it. I’d like to save the next person some trouble!

Platform Info

$ npm --versions
{ '@nymdev/sites': '0.15.333',
  npm: '5.5.1',
  ares: '1.10.1-DEV',
  cldr: '31.0.1',
  http_parser: '2.7.0',
  icu: '59.1',
  modules: '57',
  nghttp2: '1.25.0',
  node: '8.9.0',
  openssl: '1.0.2l',
  tz: '2017b',
  unicode: '9.0',
  uv: '1.15.0',
  v8: '6.1.534.46',
  zlib: '1.2.11' }
$ node -p process.platform

A co-worker passed on to me a traceback of the warning, I hope that could help!

(node:18613) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:280:19)
    at process.addListener (events.js:297:10)
    at /Users/XXXXXXXXX/.nvm/versions/node/v8.9.0/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/node_modules/signal-exit/index.js:122:15
    at Array.filter (<anonymous>)
    at load (/Users/XXXXXXXXX/.nvm/versions/node/v8.9.0/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/node_modules/signal-exit/index.js:120:21)
    at module.exports (/Users/XXXXXXXXX/.nvm/versions/node/v8.9.0/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/node_modules/signal-exit/index.js:35:5)
    at Gauge._enableEvents (/Users/XXXXXXXXX/.nvm/versions/node/v8.9.0/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/index.js:150:26)
    at Gauge.enable (/Users/XXXXXXXXX/.nvm/versions/node/v8.9.0/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/index.js:132:23)
    at EventEmitter.log.enableProgress (/Users/XXXXXXXXX/.nvm/versions/node/v8.9.0/lib/node_modules/npm/node_modules/npmlog/log.js:84:14)
    at stopRunning (/Users/XXXXXXXXX/.nvm/versions/node/v8.9.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:19:45)
    at ChildProcess.<anonymous> (/Users/XXXXXXXXX/.nvm/versions/node/v8.9.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:44:24)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

Here’s a script to reproduce the issue:

#!/usr/bin/env bash

package_json () {
  echo "{\"name\": \"$1\", \"version\": \"0.0.1\", \"scripts\": {\"postinstall\": \"echo b\"}}"

mkdir a
cd a
package_json a > package.json
cd ..

for i in {1..11}
  mkdir "b$i"
  cd "b$i"
  package_json "b$i"> package.json
  cd ..

cd a
npm i ../b{1..11}

I can confirm the change removes the warning for me, too. I’m not part of the team, but given the responses in the thread you linked, it seems safe to make a PR. They’ll review it before accepting anyway.

Yes, a PR for this would be delightful. Thank you!