用于构建 Socket.io 的 Node-Gyp 无法打开 winsock2.h (Windows 10 64x)

Node-Gyp to build Socket.io not working can't open winsock2.h (Windows 10 64x)

像这样的问题似乎很猖獗,但我发现 none 解决了我在 运行 npm install --save socket.io 时无法编译的问题。下面的当前错误(又名错误 #4)正在阻止 socket.io 的构建。首先,我在几天前发现了这个 solutions, followed by this solution. Finally, found this post on GitHub where I've installed Visual C++ build tools 建议,但仍然无法成功完成构建。还有其他建议吗?

当前错误

$ npm install --save socket.io
npm WARN package.json @ No repository field.
npm WARN package.json @ No license field.

> utf-8-validate@1.2.1 install D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild


D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate>if not defined npm_config_node_gyp (node "D:\installs\nodejs\node_modules\npm\bin\node-gyp-bin\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version  number. [D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate\build\validation.vcxproj]
  validation.cc
c:\users\mtpultz\.node-gyp.2.2\include\node\uv-win.h(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory [D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules \utf-8-validate\build\validation.vcxproj]
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 (D:\installs\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:270: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.10240
gyp ERR! command "D:\installs\nodejs\node.exe" "D:\installs\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
gyp ERR! node -v v4.2.2
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok

> bufferutil@1.2.1 install D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild

这似乎很复杂,因此在此 nodejs 应用程序中可能需要 socket.io。

好的,如果您同时选中这两个 SDK 8 and 10 when installing VS C++ Build Tools

或者,您也可以将其拉入 Homestead 和 运行 npm install --save socket.io 等虚拟机中,但上述解决方案确实适用于 Windows 10.