【KAWAKO】解决npm ERR! Cannot read property 'insert' of undefined
记录一次遇到npm报错并解决的过程
问题描述
使用npm安装东西是出现报错
root@8cf8de1c5b74:/# npm install -g pnpm
npm ERR! Cannot read property 'insert' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-07-31T08_55_13_778Z-debug-0.log
查看一下log:
root@8cf8de1c5b74:/# cat root/.npm/_logs/2023-07-31T08_55_13_778Z-debug-0.log
0 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install', '-g', 'pnpm' ]
1 info using npm@8.5.1
2 info using node@v12.22.9
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:/usr/share/nodejs/npm/npmrc Completed in 2ms
6 timing config:load:builtin Completed in 3ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/root/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/etc/npmrc Completed in 1ms
13 timing config:load:global Completed in 1ms
14 timing config:load:validate Completed in 1ms
15 timing config:load:credentials Completed in 1ms
16 timing config:load:setEnvs Completed in 1ms
17 timing config:load Completed in 12ms
18 timing npm:load:configload Completed in 12ms
19 timing npm:load:setTitle Completed in 1ms
20 timing config:load:flatten Completed in 3ms
21 timing npm:load:display Completed in 4ms
22 verbose logfile /root/.npm/_logs/2023-07-31T08_55_13_778Z-debug-0.log
23 timing npm:load:logFile Completed in 5ms
24 timing npm:load:timers Completed in 0ms
25 timing npm:load:configScope Completed in 0ms
26 timing npm:load Completed in 23ms
27 timing arborist:ctor Completed in 1ms
28 silly logfile start cleaning logs, removing 2 files
29 timing idealTree:init Completed in 7ms
30 timing idealTree:userRequests Completed in 3ms
31 silly idealTree buildDeps
32 silly fetch manifest pnpm@*
33 silly placeDep ROOT pnpm@ OK for: want: *
34 timing idealTree:#root Completed in 149ms
35 timing idealTree:node_modules/pnpm Completed in 0ms
36 timing idealTree:buildDeps Completed in 149ms
37 timing idealTree:fixDepFlags Completed in 0ms
38 timing idealTree Completed in 162ms
39 timing command:install Completed in 200ms
40 verbose stack TypeError: Cannot read property 'insert' of undefined
40 verbose stack at CacheEntry.store (/usr/share/nodejs/npm/node_modules/make-fetch-happen/lib/cache/entry.js:325:27)
40 verbose stack at cacheFetch (/usr/share/nodejs/npm/node_modules/make-fetch-happen/lib/cache/index.js:18:18)
40 verbose stack at processTicksAndRejections (internal/process/task_queues.js:97:5)
40 verbose stack at async fetch (/usr/share/nodejs/npm/node_modules/make-fetch-happen/lib/fetch.js:98:7)
40 verbose stack at async Arborist.[nodeFromEdge] (/usr/share/nodejs/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1082:19)
40 verbose stack at async Arborist.[buildDepStep] (/usr/share/nodejs/@npmcli/arborist/lib/arborist/build-ideal-tree.js:951:11)
40 verbose stack at async Arborist.buildIdealTree (/usr/share/nodejs/@npmcli/arborist/lib/arborist/build-ideal-tree.js:215:7)
40 verbose stack at async Arborist.reify (/usr/share/nodejs/@npmcli/arborist/lib/arborist/reify.js:152:5)
40 verbose stack at async Install.exec (/usr/share/nodejs/npm/lib/commands/install.js:157:5)
40 verbose stack at async module.exports (/usr/share/nodejs/npm/lib/cli.js:66:5)
41 verbose cwd /
42 verbose Linux 5.15.0-72-generic
43 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "pnpm"
44 verbose node v12.22.9
45 verbose npm v8.5.1
46 error Cannot read property 'insert' of undefined
47 verbose exit 1
48 timing npm Completed in 444ms
49 verbose unfinished npm timer reify 1690793714016
50 verbose unfinished npm timer reify:loadTrees 1690793714050
51 verbose code 1
52 error A complete log of this run can be found in:
52 error /root/.npm/_logs/2023-07-31T08_55_13_778Z-debug-0.log
chatgpt4解决过程
这是由于 Node.js 的版本过低导致的问题,你正在使用的 Node.js 版本是 12.22.9,而 npm 的版本是 8.5.1,这可能导致了一些兼容性问题。因为在 npm 的高版本中,可能使用了一些在低版本的 Node.js 中不存在的特性。
解决方案是升级你的 Node.js 版本。可以通过 Node.js 的官网进行下载安装,也可以通过 Node Version Manager (NVM) 来进行管理和升级。如果你还没有安装 NVM,你可以通过下面的命令来进行安装:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
安装完 NVM 后,你可以通过下面的命令来安装最新版的 Node.js:
nvm install node
安装完毕后,你可以通过 node -v
来查看 Node.js 的版本是否升级成功。如果显示的版本号高于你之前的版本,那么就表示升级成功了。
然后你可以尝试重新运行 npm install -g pnpm
来看看问题是否解决。
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
KAWAKO!
喜欢就支持一下吧
打赏
微信
支付宝