简体   繁体   English

由于 node-gyp 无法安装 npm:binding.gyp not found

[英]Cannot npm install due to node-gyp: binding.gyp not found

I have been working on this all day and have tried lots of different things:我整天都在做这件事,并尝试了很多不同的事情:

  • Uninstalling node and installing latest version卸载节点并安装最新版本
  • Using the --msvs_version= flag set to 2010, 2011, 2012, 2013, 2015使用--msvs_version=标志设置为2010, 2011, 2012, 2013, 2015
  • Deleting the .node-gyp folder删除 .node-gyp 文件夹
  • Adding python path to .npmrc like so: python=C:\Python27\python.exe像这样将 python 路径添加到 .npmrc: python=C:\Python27\python.exe
  • npm -g install npm@next
  • Running node-gyp rebuild and node-gyp configure运行node-gyp rebuildnode-gyp configure
  • Following Robert Kehoe's guide遵循罗伯特基欧的指南

Rough times.艰难时期。

The package is an Electron/React app and I am running Windows 10. Console output for npm install is该软件包是一个 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

And for node-gyp rebuild :对于node-gyp rebuild

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

I am well out of my wheelhouse here and would appreciate any suggestions or information in addition to solutions.我已经离开了我的驾驶室,除了解决方案之外,我将不胜感激任何建议或信息。

I am using macos catalina 10.15.5 and i faced the same issues and all the above solutions didn't worked for me.我正在使用 macos catalina 10.15.5,我遇到了同样的问题,上述所有解决方案都对我不起作用。 I was able to resolve this by running我能够通过运行来解决这个问题

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

Hope this helps people.希望这对人们有所帮助。

create a binding.gyp file and place it in your project root.创建一个binding.gyp文件并将其放在您的项目根目录中。 the content of the file looks like this:该文件的内容如下所示:

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

A binding.gyp file describes the configuration to build your module, in a JSON-like format. binding.gyp文件以类似 JSON 的格式描述构建模块的配置。 This file gets placed in the root of your package, alongside package.json.该文件与 package.json 一起放置在包的根目录中。 see here: https://github.com/nodejs/node-gyp#the-bindinggyp-file见这里: https ://github.com/nodejs/node-gyp#the-bindinggyp-file

See this thread , maybe it helps.看到这个线程,也许它有帮助。

node-gyp uses Visual Studio for building on Windows, so I guess the issue comes from your VS installation. node-gyp 使用 Visual Studio 在 Windows 上构建,所以我猜这个问题来自你的 VS 安装。

Judging from this path (C:\Program Files (x86)\MSBuild), looks like it requires a newer version (perhaps Visual Studio 2015 where MSBuild was first introduced).从这个路径(C:\Program Files (x86)\MSBuild)来看,看起来它需要更新的版本(可能是首次引入MSBuild的 Visual Studio 2015)。

Try downgrade npm version to v6:尝试将 npm 版本降级到 v6:

npm install -g npm@6 

or downgrade node version to v12 together use nvm或将节点版本降级到 v12 一起使用nvm

Ref: https://github.com/nodejs/node-gyp/issues/508参考: https ://github.com/nodejs/node-gyp/issues/508

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

Had tried so many solutions, this one seemed to work instantly for me.尝试了这么多解决方案,这个似乎对我立即起作用。 Install g++ and cmake, with command 'apt install make g++', for windows I believe these have thier website for downloading.使用命令“apt install make g++”安装 g++ 和 cmake,对于 Windows,我相信这些有他们的网站可供下载。

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

I haven't tested this for windows, this worked for me with the apt command on Linux.我还没有在 Windows 上测试过这个,这对我在 Linux 上的 apt 命令有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM