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



类似的问题似乎很普遍,但我发现的问题都不能解决我在运行npm install --save socket.io时无法编译的问题。下面的当前错误(又名错误#4)阻止了socket.io的构建。首先我找到了这个解决方案,然后是这个解决方案。最后,我在GitHub上找到了这篇文章,我在那里安装了几天前建议的Visual C++构建工具,但仍然无法成功完成构建。还有其他建议吗?

当前错误

$ 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:projectsnodejsnode_modulessocket.ionode_modulesengine.ionode_moduleswsnode_modulesutf-8-validate
> node-gyp rebuild

D:projectsnodejsnode_modulessocket.ionode_modulesengine.ionode_moduleswsnode_modulesutf-8-validate>if not defined npm_config_node_gyp (node "D:installsnodejsnode_modulesnpmbinnode-gyp-bin\....node_modulesnode-gypbinnode-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)MSBuildMicrosoft.Cppv4.0V140Microsoft.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:projectsnodejsnode_modulessocket.ionode_modulesengine.ionode_moduleswsnode_modulesutf-8-validatebuildvalidation.vcxproj]
  validation.cc
c:usersmtpultz.node-gyp4.2.2includenodeuv-win.h(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory [D:projectsnodejsnode_modulessocket.ionode_modulesengine.ionode_moduleswsnode_modules utf-8-validatebuildvalidation.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:Program Files (x86)MSBuild14.0binmsbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (D:installsnodejsnode_modulesnpmnode_modulesnode-gyplibbuild.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:projectsnodejsnode_modulessocket.ionode_modulesengine.ionode_moduleswsnode_modulesutf-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:projectsnodejsnode_modulessocket.ionode_modulesengine.ionode_moduleswsnode_modulesbufferutil
> node-gyp rebuild

这似乎很复杂,所以这个nodejs应用程序中可能需要socket.io。

好的,如果在安装VS C++构建工具时同时检查SDK 8和10,这就可以了。

或者,你也可以把它拉到像Homestead这样的虚拟机中并运行npm install --save socket.io,但上面的解决方案在Windows 10上确实有效。

最新更新