为什么在我尝试“npm i”时会出现“npm error LRUCache is not a constructor”错误?

问题描述 投票:0回答:1

每次打电话都出错

npm install
, Nodejs 版本(尝试过 18、20、22)以及我在全局或项目中调用 npm 的位置并不重要

>npm i -g pnpm@latest
npm error LRUCache is not a constructor

尝试重新安装几个版本的nodejs。 你知道会发生什么吗?我什至不知道什么是 LRUCache,我没有使用它

我的npm是10.7.0

node.js npm
1个回答
0
投票

我打开 /usr/lib64/node_modules/npm/node_modules/cacache/lib/memoization.js 并找到了这一行:

const { LRUCache } = require('lru-cache')

我把它改成这样:

const LRUCache = require('lru-cache')

这是针对 Linux 的。在 Windows 上,我想您可以在以下位置找到 memoization.js:

C:\Users\<REPLACE WITH YOUR USER FOLDER'S NAME>\AppData\Roaming\npm\node_modules\cacache\lib\memoization.js
© www.soinside.com 2019 - 2024. All rights reserved.