将节点从 v8 升级到 v14.15.4 时无法安装软件包

Can't install packages when upgraded the node from v8 to v14.15.4

我在 windows 10 上安装了 node.js v14.15.4 和 node-gyp 版本 7.1.2。 当我 运行 npm install 我得到那些错误;

gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\xxx\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\xxx\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\xxx\myProject\node_modules\mmmagic
gyp ERR! node -v v14.15.4
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
.
.
.

npm verb stack Error: mmmagic@0.4.5 install: `node-gyp rebuild`
npm verb stack Exit status 1
npm verb stack     at EventEmitter.<anonymous> (C:\Users\xxx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
npm verb stack     at EventEmitter.emit (events.js:315:20)
npm verb stack     at ChildProcess.<anonymous> (C:\Users\xxx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
npm verb stack     at ChildProcess.emit (events.js:315:20)
npm verb stack     at maybeClose (internal/child_process.js:1048:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
npm verb pkgid mmmagic@0.4.5
npm verb cwd C:\Users\x199377\AppData\Local\Programs\Git\Ego\ego\ego-app
npm verb Windows_NT 10.0.17134
npm verb argv "C:\Program Files\nodejs\node.exe" "C:\Users\xxx\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "i" "--verbose"
npm verb node v14.15.4
npm verb npm  v6.14.8
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mmmagic@0.4.5 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mmmagic@0.4.5 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 1, true ]
npm timing npm Completed in 83077ms

我按照 node-gyp 中描述的步骤进行操作,但不起作用。 PS: 我已经安装了 python 2.7 并且我安装了 python 3.8.

好像你手动安装了npm,所以你也需要更新一下:

npm install -g npm

升级后的 npm 现在有更新版本的 node-gyp

Npm 安装了一个集成的 node-gyp,它包含一个旧版本,我升级了 node-gyp:

npm install --global node-gyp@latest
for /f "delims=" %P in ('npm prefix -g') do npm config set node_gyp "%P\node_modules\node-gyp\bin\node-gyp.js"

更多详细信息,您可以查看Upgrading node-gyp independently of npm and handling multiple versions.