You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行npm install时出现“npm error LRUCache is not a constructor”错误求助

解决npm执行install时"LRUCache is not a constructor"报错的方案

核心排查方向

这个报错大概率是npm自身缓存或内部依赖损坏导致的,和你是否主动使用LRUCache无关,按以下步骤逐一尝试:

1. 清理npm缓存并重置

执行以下命令彻底清理缓存,强制npm重新拉取依赖:

npm cache clean --force

之后再尝试执行目标install命令,比如:

npm i -g pnpm@latest

2. 手动替换npm版本

当前npm 10.7.0可能存在兼容问题,尝试降级或升级npm:

  • 降级到稳定的10.x版本:
npm install -g npm@10.6.0
  • 或者升级到最新的npm版本:
npm install -g npm@latest

如果直接执行npm升级命令报错,可通过npx工具替代:

npx npm@latest install -g npm@latest

3. 彻底清理Node.js残留后重装

若之前重装Node未清理干净残留,会导致问题复发:

  • 通过系统对应方式卸载当前Node.js(Windows用控制面板、macOS用brew卸载等)
  • 删除以下残留目录:
    • Windows:C:\Users\<你的用户名>\AppData\Roaming\npm 和 C:\Users\<你的用户名>\AppData\Roaming\npm-cache
    • macOS/Linux:~/.npm 和 ~/.node-gyp
  • 重新下载官方稳定版Node.js安装包完成安装,再测试npm命令

4. 检查代理设置

网络代理可能导致npm依赖下载不完整:

  • 查看当前npm代理配置:
npm config get proxy
npm config get https-proxy
  • 若存在代理,临时禁用后重试:
npm config delete proxy
npm config delete https-proxy

内容的提问来源于stack exchange,提问作者Andrey Kuzmin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 05:42:02