【问题标题】:Cannot npm install due to node-gyp: binding.gyp not found由于 node-gyp 无法安装 npm:binding.gyp not found
【发布时间】:2017-07-27 02:34:50
【问题描述】:

我整天都在做这件事,并尝试了很多不同的东西:

  • 卸载节点并安装最新版本
  • 使用设置为2010, 2011, 2012, 2013, 2015 的--msvs_version= 标志
  • 删除 .node-gyp 文件夹
  • 将 python 路径添加到 .npmrc,如下所示:python=C:\Python27\python.exe
  • npm -g install npm@next
  • 正在运行 node-gyp rebuild 和 node-gyp configure
  • 关注Robert Kehoe's guide

艰难时期。

这个包是一个 Electron/React 应用,我运行的是 Windows 10。npm install 的控制台输出是

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\Microsoft.Cpp.x64.Targets(514,5): error MSB8008: Specif
ied platform toolset (v120) is not installed or invalid. Please make sure that a supported PlatformToolset value is sel
ected. [C:\Users\scheinerbock\Desktop\mpstudio\node_modules\mplib\build\addon.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `msbuild` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\scheinerbock\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Windows_NT 10.0.14393
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\scheinerbock\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\scheinerbock\Desktop\mpstudio\node_modules\mplib
gyp ERR! node -v v6.10.0
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok

对于node-gyp rebuild:

gyp: binding.gyp not found (cwd: C:\Users\scheinerbock\Desktop\mpstudio) 尝试加载 binding.gyp

我已经脱离了我的驾驶室,除了解决方案之外,我将不胜感激任何建议或信息。

【问题讨论】:

  • 您好 Ben,您能详细说明一下您是如何解决它的吗?更新机器的具体步骤?哪个节点版本,npm 版本,你运行了哪些确切的命令来成功?谢谢
  • @TyForHelpDude 我不再在这个项目上工作了,我什至没有我运行的计算机。所以不幸的是,我没有办法为你获取这些信息。对不起

标签: node.js windows npm node-gyp


【解决方案1】:

尝试了这么多解决方案,这个似乎立即对我有用。 安装 g++ 和 cmake,使用命令 'apt install make g++',对于 windows,我相信这些有他们的网站可供下载。

https://cmake.org/download/ - for make | https://sourceware.org/cygwin/ - for g++(如果不是在google上搜索gcc)

我还没有在 Windows 上测试过这个,这对我在 Linux 上使用 apt 命令有效。

【讨论】:

    【解决方案2】:

    我正在使用 macos catalina 10.15.5,我遇到了同样的问题,上述所有解决方案都对我不起作用。我能够通过运行解决这个问题

    npm i -g node-gyp@latest && npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"
    

    希望这对人们有所帮助。

    【讨论】:

    • 工作就像一个魅力。请注意...应该使用由特定环境确定的路径 node_gyp 。我的node-gyp.js 安装在~/.nvm/versions/node/v6.17.1/lib/node_modules/node-gyp/bin/node-gyp.js
    【解决方案3】:

    创建一个 binding.gyp 文件并将其放置在您的项目根目录中。文件内容如下所示:

    {
      "targets": [
        {
          "target_name": "binding",
          "sources": [ "src/binding.cc" ]
        }
      ]
    }
    

    binding.gyp 文件以类似 JSON 的格式描述了构建模块的配置。该文件与 package.json 一起放置在包的根目录中。看这里:https://github.com/nodejs/node-gyp#the-bindinggyp-file

    【讨论】:

    • 这对我在 macOS High Sierra 上没有影响
    • 这里的解决方案在 macOS Big Sur 上的 @Zaid Haider (stackoverflow.com/a/62108079/777885) 之后有效。仅供参考 binding.cc 可以只是一个空文件??
    【解决方案4】:

    确保您安装了 python 2.x 版本而不是 3.x 对我来说,它在我安装 python 2.6 后工作

    【讨论】:

      【解决方案5】:

      见this thread,也许有帮助。

      node-gyp 使用 Visual Studio 在 Windows 上构建,所以我猜这个问题来自你的 VS 安装。

      从这个路径来看(C:\Program Files (x86)\MSBuild),看起来它需要更新的版本(可能是 Visual Studio 2015 首次引入 MSBuild)。

      【讨论】:

      • 谢谢米海的回答。不幸的是,我确实安装了 VS2015,并且我也尝试了许多其他版本。我最终放弃了在我正在使用的旧计算机上构建项目,并成功地在新机器上构建。
      猜你喜欢
      • 2021-11-16
      • 2020-04-27
      • 2014-01-30
      • 2020-01-05
      • 2015-05-15
      • 2020-11-25
      • 2020-11-19
      • 1970-01-01
      • 2013-05-25
      相关资源
      最近更新 更多