在OSX上安装MeanJS时,`node-pre-gyp install --fallback-to-build`失败。

76

使用Windows很长时间后,我刚买了一台Mac Book。

我试着在一个我一直在做的MeanJS项目上工作。在该项目上进行npm install时会抛出错误。

Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/Aayush/Work/lishn/repo/lishn-alpha/node_modules/grunt-node-inspector/node_modules/node-inspector/node_modules/v8-debug/build/debug/v0.4.6/node-v46-darwin-x64/debug.node --module_name=debug --module_path=/Users/Aayush/Work/lishn/repo/lishn-alpha/node_modules/grunt-node-inspector/node_modules/node-inspector/node_modules/v8-debug/build/debug/v0.4.6/node-v46-darwin-x64' (1)
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.1.1
npm ERR! npm  v2.14.4
npm ERR! code ELIFECYCLE
> 
> npm ERR! v8-debug@0.4.6 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the v8-debug@0.4.6 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! This is most likely a problem with the v8-debug package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR!     npm owner ls v8-debug
npm ERR! There is likely additional logging output above.

我尝试清除缓存。

我尝试使用sudo--unsafe-perm安装node-pre-gyp。

我还尝试了安装一个新的MEAN项目,但出现了同样的错误。

我似乎找不到问题所在。

Node Version - 5.0.0

NPM Version - 3.3.10

我发现一些帖子建议降级Node和npm。 我还没有验证它是否有效。 我希望能够解决这个问题而不必降级。 - aayush shrestha
我建议至少降级到4.2.x,因为它是最新的长期支持版本,仅在几周前发布。如果它可以工作,那么尝试使用5.x来查看哪些内容会出错,有可能npm模块还没有更新以处理5.x,因为它只发布了几天?或者至少不要使用sudo与npm或node一起使用,考虑使用nvm来避免麻烦。 - jmunsch
当node-pre-gyp尝试构建时会发生什么?(这是npm错误上面的文本)。另外,您用于构建的节点版本为4.1.1 npm ERR!node v4.1.1 - jmunsch
21个回答

59

我已经尝试升级node-gyp:

sudo npm install -g node-gyp

对我有用。

我在这里找到了解决方案,希望它能帮到你。


4
只需添加注释。在npm install -g node-gyp中,-g的意思是全局安装它,而不是升级它。 - JavaNoScript
对我来说也没用。有没有其他解决这个问题的方法? - Rahul J. Rane
1
对我来说,只有安装 package-lock.json 中找到的确切版本才能正常工作。 对我来说,正确的命令是:npm i -g node-gyp@3.8.0 - Emanuele Pavanello
谢谢。这真的有效!!sudo npm install -g node-gyp - Frank Guo
1
另外,除非绝对必要,否则不要在npm中使用sudo。https://medium.com/@ExplosionPills/dont-use-sudo-with-npm-still-66e609f5f92 - shreyasm-dev
安装全局包并不是一个好的解决方案。 - Ivan P

9

russfrisch 在4天前评论:

我遇到了同样的问题。将 grunt-node-inspector 的版本更改为">="而不是"~",使其对我有效。

github页面找到这个解决方案。

我的StackoverFlow帖子链接


3
"grunt-node-inspector": "~0.4.1"设置为 Node 4.2.2,这对我起作用了。 - Dziamid
它起作用了 https://github.com/node-inspector/v8-debug/issues/7#issuecomment-154450807 - Rakesh Prabhakaran

7

看起来这是我的节点升级出了问题。不过,我通过以下方法解决了它。

首先,使用以下命令卸载CLI并清除缓存,然后重新安装:

npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli

接下来安装node-pre-gyp

npm install -g node-pre-gyp

重新启动终端,看问题是否已解决。

7

我曾经遇到过同样的问题,花费了很多精力才解决。原因是npm版本与gprc版本不兼容。所以我们需要更新npm。

npm update
npm install 

5

这个方法可能不适用于所有人,但当以上方法都无法解决问题时,我更新了node,这样问题就得到了解决。


3

只需使用此命令即可处理此错误 npm install --unsafe-perm --allow-root


谢谢你,这一直困扰我很长时间。 - Suhail Akhtar

3

我也遇到了同样的问题。我找到了解决方案。

bcrypt需要C++、Python和node-pre-gyp

sudo apt-get install g++
sudo apt-get install -y build-essential python
npm install node-pre-gyp

更多详情请查看:安装说明


2

我有相同的错误,我可以通过以下方式解决:

我需要canvas包-> https://www.npmjs.com/package/canvas

在我的情况下,我使用了MacOS,因此我安装了依赖项:

$ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

就是这样了!


1

正如@ocean800所说,我更新了node。下面的解决方案适用于Ubuntu 16.04,并且对我有用,但在OSX上类似的解决方案可能会解决此问题。

在Ubuntu 16.04上,对我有用的是升级node

在ubuntu 16.04上更新nodejs

我正在复制上面链接中的解决方案

要进行更新,您可以安装n

sudo npm install -g n

然后只需:
sudo n latest

或者一个特定的版本

sudo n 8.9.0

然后尝试安装。
sudo npm install <package>

1
在编程中,通常不建议使用sudo前缀,你应该不需要它:https://dev59.com/6l8e5IYBdhLWcg3w2dYD#29787931 - Dmitri Zaitsev

1

好的,经过一些调试,以下依赖项正在使用较旧版本的touch

./node_modules/bower/node_modules/decompress-zip/package.json:    "touch": "0.0.3"
./node_modules/bower/node_modules/lockfile/package.json:    "touch": "0"
./node_modules/gulp-nodemon/node_modules/nodemon/package.json:    "touch": "1.0.0",
./node_modules/gulp-nodemon/node_modules/touch/package.json:    "touch": "./bin/touch.js"
./node_modules/nodemon/package.json:    "touch": "~0.0.3",

有了这个,我就可以在node 5上使用meanJS了。

以下是我运行的命令历史记录:

git clone https://github.com/meanjs/mean.git
cd mean
nvm install 5
nvm use 5
npm install
which node-gyp
npm install -g node-pre-gyp
sudo xcodebuild -license
npm install

遇到了一些问题,然后:

我添加了以下行:

#!/usr/bin/env node

在文件./mean/node_modules/.bin/touch的顶部

然后:

npm install

当然,在重试之前,您可以尝试运行sudo rm -rf ./node_modules && npm cache clean 命令。


我尝试安装旧版本的 node-pre-gyp: npm install node-pre-gyp@v0.7.x。它对我有效。我不知道为什么新版本无法工作。 - Lakshmi Swetha G

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接