在macOS上使用npm安装sharp时出错

在macOS上使用npm安装sharp时出错,npm,sharp,Npm,Sharp,如果我创建了一个新的npm项目: mkdir ~/test cd ~/test npm init -y 然后尝试安装: 我收到以下错误消息: > sharp@0.18.4 install /Users/hsribei/tmp/test/node_modules/sharp > node-gyp rebuild sh: /usr/local/lib/node_modules/npm/bin/node-gyp-bin/node-gyp: Permission denied npm W

如果我创建了一个新的npm项目:

mkdir ~/test
cd ~/test
npm init -y
然后尝试安装:

我收到以下错误消息:

> sharp@0.18.4 install /Users/hsribei/tmp/test/node_modules/sharp
> node-gyp rebuild

sh: /usr/local/lib/node_modules/npm/bin/node-gyp-bin/node-gyp: Permission denied
npm WARN test@1.0.0 No description
npm WARN test@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! sharp@0.18.4 install: `node-gyp rebuild`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the sharp@0.18.4 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/hsribei/.npm/_logs/2017-09-20T19_11_03_836Z-debug.log
我找到了删除~/.node gyp的说明,尝试了一下,没有成功。删除节点_模块并重试也不起作用。像sudo一样跑步也没有帮助


有没有关于如何追踪问题所在的想法?

我发现夏普缺少一个全局依赖性

如果你跑

npm install -g node-gyp
首先,然后

它起作用了

npm install -g node-gyp
npm install --save sharp