npm 在macOS上安装或创建Node.js项目时的MaxListenersExceedWarning

bnlyeluc  于 12个月前  发布在  Mac
关注(0)|答案(2)|浏览(488)

当我尝试在macOS(达尔文)上安装或创建Node.js项目时,收到以下警告消息:
(node:80101) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
我已经更新了Node.js到最新版本(V20.5.1),因为我看到警告太多次了,npm已经是最新的(V9.8.1)。我没有使用任何第三方工具,我只是使用终端。
我得到警告后的命令是:npm install ...npx ...
在执行这些命令后,我至少收到一次警告消息(通常是多次)。
我正在做的项目甚至没有NodeJS文件,这两次我都在忙碌一个react和下一个项目(我认为这是无关紧要的,因为我在任何项目之外的终端中使用NPM时都看到了同样的警告)。
如果有人能帮我的话我会很感激的。到目前为止,除了警告本身,我还没有注意到项目或安装过程中有任何错误,但我不明白为什么当我没有对NPM或node中的任何配置进行任何更改时,会弹出警告。
尝试使用NPM安装软件包并使用NPX创建项目,这两个都导致了相同的警告(有时在安装或创建过程完成之前多次):
(node:80101) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit

wwodge7n

wwodge7n1#

以下是我的解决方案:

npm doctor

它能解决所有问题
请确保您的注册表是https://registry.npmjs.org//opt/homebrew/bin/.keepme可执行

fwzugrvs

fwzugrvs2#

我这样做解决了我的问题,因为任何人都会回来解决同样的问题:

感谢Lisheng Ma和JSON Derulo的回答和推荐使用npm doctor,我设法解决了这个问题,如下所示:
我首先运行npm doctor,得到以下输出:

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`

所以我更新了NPM,并运行了以下命令(我使用的是macOS):
npm install -g npm@latest,解决NPM版本警告。
sudo chmod +x /opt/homebrew/bin/.keepme /opt/homebrew/bin/__pycache__/bottle.cpython-310.pyc,解决doctor命令输出中的权限错误。
最后,我再次运行npm doctor,得到以下输出:

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

我认为问题是与权限,不知道如何!但现在肯定是修好了。

  • 欢呼编码!*

相关问题