I am getting the following warning message when I try to install or create Node.js projects on macOS (darwin):
(node:80101) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
I have updated Node.js to the latest version (V20.5.1) after I was seeing the warning for too many times, and npm was already up to date (V9.8.1). I'm not using any third-party tools, and I simply use terminal.
The commands I get the warning after are:
npm install ...
and
npx ...
.
I get the warning message at least once after executing these commands (usually multiple times).
The projects I was working on didn't even have NodeJS files, both times I was busy on a react and next project (which I think is irrelevant, because I see the same warning when using NPM in terminal outside any projects).
I'd appreciate if anyone can help me with this. So far I haven't noticed anything wrong in projects or installing process except the warning itself, but I don't understand why should the warning pop-up when I haven't made any changes to any configurations in NPM or node.
Tried installing packages with NPM and creating projects with NPX, which both resulted the same warning (sometimes multiple times before the completion of install or create process):
(node:80101) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
I solved my problem doing so, for anyone comes back for the same problem:
Thanks to Lisheng Ma & JSON Derulo for their answer and recommendation to use npm doctor
, I managed to solve the problem as below:
I first ran npm doctor and I got the following output:
Check Value Recommendation/Notes
npm ping ok
npm -v not ok Use npm v10.0.0
node -v ok current: v20.5.1, recommended: v20.5.1
npm config get registry ok using default registry (https://registry.npmjs.org/)
git executable in PATH ok /opt/homebrew/bin/git
global bin folder in PATH ok /opt/homebrew/bin
Perms check on cached files ok
Perms check on local node_modules ok
Perms check on global node_modules ok
Perms check on local bin folder ok
npm ERR! checkFilesPermission Missing permissions on /opt/homebrew/bin/.keepme (expect: executable)
npm ERR! checkFilesPermission Missing permissions on /opt/homebrew/bin/__pycache__/bottle.cpython-310.pyc (expect: executable)
Perms check on global bin folder not ok Check the permissions of files in /opt/homebrew/bin
npm WARN verifyCachedFiles Content garbage-collected: 2266 (1602671184 bytes)
npm WARN verifyCachedFiles Cache issues have been fixed
Verify cache contents ok verified 7508 tarballs
npm ERR! Some problems found. See above for recommendations.
npm ERR! A complete log of this run can be found in: `path name to the log file`
So I updated NPM, and ran the following commands (I'm using macOS):
npm install -g npm@latest
, to resolve the warning about the NPM version.
sudo chmod +x /opt/homebrew/bin/.keepme /opt/homebrew/bin/__pycache__/bottle.cpython-310.pyc
, to resolve the permission errors in the output of doctor command.
Finally, I ran npm doctor
again and I got the following output:
Check Value Recommendation/Notes
npm ping ok
npm -v ok current: v10.0.0, latest: v10.0.0
node -v ok current: v20.5.1, recommended: v20.5.1
npm config get registry ok using default registry (https://registry.npmjs.org/)
git executable in PATH ok /opt/homebrew/bin/git
global bin folder in PATH ok /opt/homebrew/bin
Perms check on cached files ok
Perms check on local node_modules ok
Perms check on global node_modules ok
Perms check on local bin folder ok
Perms check on global bin folder ok
Verify cache contents ok verified 7509 tarballs
I think the problem was with the permissions, Have no idea how! But it definitely is fixed now.
cheers coding!