MaxListenersExceededWarning when installing or creating Node.js projects on macOS
Asked Answered
I

3

12

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

Immoderation answered 21/8, 2023 at 8:43 Comment(1)
Please provide enough code so others can better understand or reproduce the problem.Bise
I
14

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!

Immoderation answered 4/9, 2023 at 10:39 Comment(1)
Thanks, solved my problem on WSL as well with npm doctor. In my case it is because I had volta interfering with the npm version, so I was not using the last one available.Implore
F
4

Here is my solution:

npm doctor

It solves all problems

Make sure your registry is https://registry.npmjs.org/ and /opt/homebrew/bin/.keepme is executable

Ferial answered 27/8, 2023 at 13:10 Comment(1)
You were absolutely right! So I ran npm doctor and found there are issues with NPM version (which isn't an issue, since the new version came after I posted here) and a few permission stuff. I'll put details in an answer, but a single command fixed the permission issues and now everything works seamlessly. Thanks to you!Immoderation
E
1

In my organisation this error appears in case you havent set the proxy in npm config.

npm proxy can be set like:

$ npm config set proxy YOUR_PROXY_ADDRESS $ npm config set https-proxy YOUR_PROXY_ADDRESS

Eider answered 21/11, 2023 at 13:19 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.