You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

执行npm install时遭遇MaxListenersExceededWarning警告及ECONNRESET网络错误求助

执行npm install时遭遇MaxListenersExceededWarning警告及ECONNRESET网络错误求助

最近跑npm install的时候碰到了一堆烦人的警告,还直接报了网络错误,折腾半天没搞定,来求助各位大佬!

先把报错信息贴出来:

(node:5156) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
(node:5156) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit

npm ERR! code ECONNRESET
npm ERR! syscall read
npm ERR! errno ECONNRESET
npm ERR! network request to https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz failed, reason: read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in: C:\Users\xxxx\AppData\Local\npm-cache_logs\2023-11-10T15_52_29_865Z-debug-0.log

整理了一些可能的解决方法,大家可以参考:

  • 优先解决网络问题(主因):ECONNRESET是连接重置错误,大概率是网络不稳定或者代理配置不对导致的,那个监听器警告可能是网络重试次数多了触发的连锁反应
    1. 测试网络连通性:先手动访问报错里的包地址https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz,看看能不能正常下载。如果打不开,先检查本地网络,或者切换成手机热点试试
    2. 检查代理配置:要是在公司/校园网环境下,代理很可能是问题根源。先查看当前npm的代理设置:
      npm config get proxy
      npm config get https-proxy
      
      不需要代理的话,直接清空:
      npm config delete proxy
      npm config delete https-proxy
      
      需要代理的话,设置正确的代理地址(替换成你自己的代理地址和端口):
      npm config set proxy http://proxy.example.com:8080
      npm config set https-proxy http://proxy.example.com:8080
      
    3. 切换npm镜像源:官方源在国内访问有时候不太稳定,可以换成国内的镜像源试试,比如淘宝镜像:
      npm config set registry https://registry.npmmirror.com/
      
  • 处理监听器警告:如果网络问题解决后还出现这个警告,可以临时调整Node的监听器上限,执行install前先设置环境变量:
    # Windows命令行
    set NODE_OPTIONS=--max-listener=100
    # Linux/macOS终端
    export NODE_OPTIONS=--max-listener=100
    
    之后再执行npm install就行,这个只是临时调整,一般网络问题解决后警告也会跟着消失
  • 清理缓存重新安装:有时候缓存损坏也会导致各种奇怪的问题,试试清理缓存后重装:
    npm cache clean --force
    # Windows删除node_modules和lock文件
    rmdir /s /q node_modules
    del package-lock.json
    # Linux/macOS
    rm -rf node_modules package-lock.json
    npm install
    

备注:内容来源于stack exchange,提问作者PoeEinsam

火山引擎 最新活动