需要 node-gyp 的 npm install 在 Windows 上失败

新手上路,请多包涵

我有一个使用 bufferutilsutf-8-validate 的 NPM 项目,两者都需要 node-gyp 来安装它们。当我做 npm install 时,我收到以下错误:

 > bufferutil@1.2.1 install C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil
> node-gyp rebuild

C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil {git}{hg}
{lamb} if not defined npm_config_node_gyp (node "C:\Users\Marek\AppData\Roaming\npm\node_modules\npm\bin\node-g
yp-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.
  bufferutil.cc
C:\Users\Marek\.node-gyp\5.1.1\include\node\v8.h(18): fatal error C1083: Cannot open include file: 'stddef.h':
 No such file or directory [C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil\build\bufferutil.vcx
proj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\Marek\AppData\Roaming\npm\node_modules\npm\node_modules\nod
e-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:\\Users\\Marek\\AppData\\Roaming\\npm\\node_modules\\
npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil
gyp ERR! node -v v5.1.1
gyp ERR! node-gyp -v v3.2.1
gyp ERR! not ok
npm WARN install:bufferutil@1.2.1 bufferutil@1.2.1 install: `node-gyp rebuild`
npm WARN install:bufferutil@1.2.1 Exit status 1

以前因为没有安装 Python 2.7 而失败,现在是这个。这让我很头疼。我该怎么办?

原文由 Marek Lisý 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.2k
2 个回答

下面的答案代表手动安装,但有一种更简单的方法:自动安装。

以管理员身份打开 Powershell 并运行 npm install -g windows-build-tools

安装需要时间,但它对我来说就像一个魅力!

原文由 Manuel Beaudru 发布,翻译遵循 CC BY-SA 4.0 许可协议

我在 GitHub 上找到了这个 绝妙的解决方案

  1. 您的操作系统必须是 Windows
  2. 通过在控制台中 python --version 来检查 python 是否在您的路径中。如果不是那么
  3. 下载 python 2.7(我推荐 chocolatey ( choco install python2 -y ))并将 python.exe 添加到您的 PATH 变量中。
  4. 你不是在Windows 7上吗?跳过 5 和 6。
  5. 检查您是否安装了 .NET 4.5.1+ 。如果不是那么
  6. 下载并安装 .NET 4.5.1 (.NET 4.5.2 也可以正常工作)
  7. 下载 Microsoft Visual C++ Build Tools 2015 技术预览
  8. 使用自定义安装。如果尚未安装 Windows 8.1 SDK,请安装。显然,您使用的是什么操作系统并不重要。您只需要 Windows 8.1 SDK。
  9. 将 npm 配置变量 msvs_version 设置为 2015: npm config -g set msvs_version 2015
  10. 在以 node-gyp 作为依赖项的任何项目中执行 npm i ,而不会看到奇怪的错误消息

我的噩梦消失了!

原文由 Marek Lisý 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题