node.js 尝试配置或重建 node-gyp 时,出现错误:mac osx Mavericks

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20911930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:35:30  来源:igfitidea点击:

when trying to configure or rebuild node-gyp, getting errors: mac osx mavericks

macosnode.jsosx-mavericksnode-gyp

提问by gabriella

I'm trying to run node-gyp configure, but am getting the following errors:

我正在尝试运行node-gyp configure,但出现以下错误:

gyp: binding.gyp not found (cwd: /usr/local/bin)
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 13.0.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "configure"
gyp ERR! cwd /usr/local/bin
gyp ERR! node -v v0.10.20
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok 

I think that I'm in the wrong directory, but I'm not sure. Which directory should I be in to run this?

我认为我在错误的目录中,但我不确定。我应该在哪个目录中运行它?

回答by h0x91B

You are trying to run node-gyp rebuildin current working directory (CWD) /usr/local/binso the node-gypcan not find binding at /usr/local/bin/binding.gyp.

您正在尝试node-gyp rebuild在当前工作目录 (CWD) 中运行,/usr/local/bin因此node-gyp无法在/usr/local/bin/binding.gyp.

Navigate your terminal to a directory which contains NodeJS module and only then run node-gyp rebuild.

将终端导航到包含 NodeJS 模块的目录,然后才运行node-gyp rebuild.

cd ~/Projects/your-nodejs-native-module/
node-gyp rebuild

BTW I am not sure from which node version exactly but in modern versions, you can just run npm installin this directory and npm will run node-gyp rebuildfor you.

顺便说一句,我不确定确切来自哪个节点版本,但在现代版本中,您可以npm install在此目录中运行,npm 将为node-gyp rebuild您运行。

cd ~/Projects/your-nodejs-native-module/
npm install

回答by eljefedelrodeodeljefe

if in doubt first re-install npm install -g node-gyp.

如果有疑问,请先重新安装npm install -g node-gyp

It's best practice to run node-gyp rebuild. Run it from your project's root. Also your binding.gypshould be in the root, pointing to dependencies (somewhere else).

运行node-gyp rebuild. 从项目的根目录运行它。您也binding.gyp应该在根目录中,指向依赖项(其他地方)。

In general there shouldn't be any need to run node-gyp configuremanually.

一般来说,不需要node-gyp configure手动运行。

回答by dagonza

By the look of the things (not 100% sure) /usr/local/bindoes not exist in your computer. But it is hard to say from the stack-trace.

从外观上看(不是 100% 确定)/usr/local/bin,您的计算机中不存在。但是从堆栈跟踪很难说。

回答by Zach Janicki

I have had this problem with newer versions of node. My best work around has been using something like node version manager (nvm) to revert back to an older version of node and then running npm installagain.

我在较新版本的节点上遇到了这个问题。我最好的解决方法是使用节点版本管理器 (nvm) 之类的东西来恢复到旧版本的节点,然后npm install再次运行。

回答by ShahNewazKhan

Install node-gyp globally first:

首先全局安装 node-gyp:

sudo npm -g install node-gyp

Please see this answer

请看这个答案