17

我是 Node.js 和 NPM 的新手。我正在使用 Node v0.10.0,当我运行 npm install socket.io 命令时,我收到以下错误:

C:\Users\USER\AppData\Roaming\npm\node_modules\socket.io\node_modules\socket.io-
client\node_modules\ws>node "C:\Users\USER\AppData\Roaming\npm\node_modules\npm\
bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(29
7,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.
TargetFrameworkVersion or PlatformToolset may be set to an invalid version nu
mber. [C:\Users\USER\AppData\Roaming\npm\node_modules\socket.io\node_modules\so
cket.io-client\node_modules\ws\build\bufferutil.vcxproj]
bufferutil.cc
c:\users\user\.node-gyp\0.10.0\deps\uv\include\uv-private/uv-win.h(32): fatal e
rror C1083: Cannot open include file: 'winsock2.h': No such file or directory [
C:\Users\USER\AppData\Roaming\npm\node_modules\socket.io\node_modules\socket.io
-client\node_modules\ws\build\bufferutil.vcxproj]

我想这是一个构建错误,所以我花了很多时间谷歌搜索和更新我的 Windows SDK、Visual Studio、.Net Framework 等。在一种或另一种形式中,我得到了上述错误。根据此链接https://connect.microsoft.com/VisualStudio/feedback/details/713415/erroneous-windows-sdk-x64-compilation-warning警告可能是错误的,因为我在 x64 机器上。我确实看到 winsock2.h 位于 C:\Program Files\Microsoft SDKs\Windows\v7.1\Include 并已将其包含在我的路径中。我的路径包含以下内容:

C:\Program Files\nodejs\;
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\vcpackages;
C:\Program Files\Microsoft Windows Performance Toolkit\;
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include;
C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib;
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include;
C:\Program Files\Debugging Tools for Windows (x64)\winext\manifest;
C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;

与此路径相同的错误。有任何想法吗?

4

4 回答 4

10

我在尝试 npm install socket.io 时搜索了一个类似的问题

从这里https://github.com/LearnBoost/socket.io/issues/1151#issuecomment-16015421

我最终设置了这个环境变量:

set GYP_MSVS_VERSION=2013

这是在安装 Windows SP1(准备安装程序)之后,然后是 SP1 安装程序,然后是 Windows 更新的 101 更新,然后是 VS 2013 Express。

真的很容易:-/

于 2014-05-25T20:10:41.840 回答
5

Windows 7 x64 上的节点安装存在问题。基本上,在使用 msbuild 构建解决方案时,您必须明确指定平台工具集。这是一个对我有用的解决方案:在您的终端运行中:

调用“C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd”/Release /x64

然后运行

npm 安装 socket.io

更多信息在这里

于 2014-10-09T17:53:42.173 回答
2

因此,尽管我对以管理员身份运行 shell 发表了评论,但我在另一台仍然以管理员身份运行 shell 的机器上遇到了这个问题。

(为了搜索引擎的利益,下面是一个非常完整的错误摘录)

这些错误似乎与node-gyp我无法独立安装有关,并找到了一些有用的注释

你需要:

  • Microsoft Visual Studio C++ 2010(Express 版本运行良好)
    • 我确实已经有了这个
  • 对于节点和本机模块的 64 位构建,您还需要Windows 7 64 位 SDK
    • 这个安装一直失败,然后我发现
    • _如果您拥有比 Visual C++ 2010 x86 Redistributable 版本 10.0.30319 更新的 vcredist_x86.exe,则不会安装 SDK 7.1。_

  • 我卸载了 10.0。[东西 > 30319]
  • 安装了 SDK 7.1
  • 然后能够npm i -g node-inspector没有问题(socket.io是一个依赖)

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(296,5): warning MSB800
3: Could not find VCInstallDir variable from the registry.  TargetFrameworkVersion or PlatformTools
et may be set to an invalid version number. [C:\Users\Michael Paulukonis\AppData\Roaming\npm\node_m
odules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]

  bufferutil.cc

c:\users\michael paulukonis\.node-gyp\0.10.5\deps\v8\include\v8stdint.h(33): fatal error C1083: Can
not open include file: 'stddef.h': No such file or directory [C:\Users\Michael Paulukonis\AppData\R
oaming\npm\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vc
xproj]

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(296,5): warning MSB800
3: Could not find VCInstallDir variable from the registry.  TargetFrameworkVersion or PlatformTools
et may be set to an invalid version number. [C:\Users\Michael Paulukonis\AppData\Roaming\npm\node_m
odules\socket.io\node_modules\socket.io-client\node_modules\ws\build\validation.vcxproj]

  validation.cc

c:\users\michael paulukonis\.node-gyp\0.10.5\deps\v8\include\v8stdint.h(33): fatal error C1083: Can
not open include file: 'stddef.h': No such file or directory [C:\Users\Michael Paulukonis\AppData\R
oaming\npm\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\validation.vc
xproj]
于 2013-11-23T03:16:48.483 回答
2

您是否以足够的权限启动 CMD 提示符?我偶尔遇到了 npm install 的问题。

如果是这种情况,请以管理员身份运行 CMD。

于 2013-05-12T14:41:37.020 回答