npm 安装失败,出现错误 C2373,vs2015 更新 3

npm install fails with error C2373 with vs2015 update 3

用 windows 10 重新安装我的机器后,用 Visual Studio 2015 设置它 我在安装我的 git 存储库时遇到了这个错误:

npm install 在不同的项目上失败:

...
C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_load_hook.c(34): error C2373: "__pfnDliNotifyHook2": [...]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Windows_NT 10.0.10586
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\...\node_modules\buffertools
gyp ERR! node -v v4.4.7
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

此错误与 npmnode-gypVisual Studio 2015 相关,并且已在 node-gyp@3.4.0 中修复,但 npm 仍指向一个旧版。作为解决方法,我可以提出以下建议:

  1. 转到安装 npm 的文件夹,例如: C:\Program Files\nodejs\node_modules\npm

  2. 打开:package.json

  3. 删除 bundleDependencies

  4. node-gyp 的条目
  5. dependencies

  6. 中将node-gyp的版本号改为3.4.0
  7. 在此目录下制作一个npm i安装node-gyp@3.4.0修复问题

可在此处找到相关 GitHub 问题:

  1. nodejs/node#7286
  2. nodejs/node-gyp#956
  3. npm/npm#13199
  4. npm/npm#13200

另一种不涉及 npm 安装的替代解决方案是 运行

SET CL=-DDELAYIMP_INSECURE_WRITABLE_HOOKS %CL%

在运行宁npm install

之前

或更新 npm:

npm install npm -g