我正在使用MacOS Sierra v10.12.6,我编写了命令npm update -g
并得到了结果
npm WARN npm npm does not support Node.js v5.3.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
npm ERR! Buffer.alloc is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/demiryil/.npm/_logs/2017-11-21T08_43_54_258Z-debug.log
打印出的日志
0 info it worked if it ends with ok
1 warn npm npm does not support Node.js v5.3.0
2 warn npm You should probably upgrade to a newer version of node as we
3 warn npm can't make any promises that npm will work with this version.
4 warn npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
5 warn npm You can find the latest version at https://nodejs.org/
6 verbose cli [ '/usr/local/Cellar/node/5.3.0/bin/node',
6 verbose cli '/usr/local/bin/npm',
6 verbose cli 'update',
6 verbose cli '-g' ]
7 info using npm@5.5.1
8 info using node@v5.3.0
9 verbose stack TypeError: Buffer.alloc is not a function
9 verbose stack at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/tar/lib/pack.js:32:20)
9 verbose stack at Module._compile (module.js:398:26)
9 verbose stack at Object.Module._extensions..js (module.js:405:10)
9 verbose stack at Module.load (module.js:344:32)
9 verbose stack at Function.Module._load (module.js:301:12)
9 verbose stack at Module.require (module.js:354:17)
9 verbose stack at require (internal/module.js:12:17)
9 verbose stack at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/tar/lib/create.js:6:14)
9 verbose stack at Module._compile (module.js:398:26)
9 verbose stack at Object.Module._extensions..js (module.js:405:10)
9 verbose stack at Module.load (module.js:344:32)
9 verbose stack at Function.Module._load (module.js:301:12)
9 verbose stack at Module.require (module.js:354:17)
9 verbose stack at require (internal/module.js:12:17)
9 verbose stack at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/tar/index.js:4:30)
9 verbose stack at Module._compile (module.js:398:26)
10 verbose cwd /Users/demiryil/Documents/JS projects/katanio
11 verbose Darwin 16.7.0
12 verbose argv "/usr/local/Cellar/node/5.3.0/bin/node" "/usr/local/bin/npm" "update" "-g"
13 verbose node v5.3.0
14 verbose npm v5.5.1
15 error Buffer.alloc is not a function
16 verbose exit [ 1, true ]
搜索了一段时间后,我发现此命令适用于人sudo npm uninstall -g npm
,但是在尝试卸载npm时遇到完全相同的错误。
那么如何更新我的npm?
答案 0 :(得分:1)
您正在使用的Node.js版本5.3.0
严重过时。您已经安装了最新的npm版本(5.5.1
),但这是包管理器,并且它不会在这样一个过时的Node.js上运行,因为它依赖于稍后添加的功能。正如您在错误消息中看到的那样,它使用Buffer.alloc
,该版本中不存在。
您需要升级Node.js(运行时),而不是npm(包管理器)。当您运行npm update -g
时,它只会更新由npm安装的软件包。
看起来你已经用Homebrew安装了Node.js,所以你可以使用以下命令升级它:
brew update
brew upgrade node