6

关于macOS的node-gyp rebuild error

 2 years ago
source link: https://shiau.xyz/5045121d99cd/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

关于macOS的node-gyp rebuild error

2021-03-242 分钟

在使用npm安装一些包的时候,很容易遇到关于node-gyp rebuild的error。

image-20210324181624390.png

造成这个问题的原因,一般都是系统内缺少node-gyp的依赖库。因此,解决问题的思路就是:

  • 查看缺少什么库
  • 安装缺少的库

Google「node-gyp rebuild error」,排名比较靠前的中文内容,一般都会讲如何解决没有安装Xcode Command Line Tools的问题,比如这篇文章

如果报错的内容中,存在「gyp: No Xcode or CLT version detected!」,那就得安装Xcode CLT:

xcode-select --install

在这之后,如果继续报错,就得检查缺少什么依赖了。一般来说,在一大段报错信息的后半部分,可以找到「No package ‘xxx’ found」这样的的错误信息。

image-20210324183746352.png

比如上图,提示缺少pixman-1,那就使用Homebrew安装pixman。

brew install pixman

一般不会这么顺利,安装缺少的依赖后,执行npm会继续报错,那就继续安装缺少的依赖。

image-20210324182923717.png
brew install cairo

image-20210324183859524.png

brew install pango

为了避免反复尝试,总结一下。在macOS Big Sur,解决node-gyp rebuild error的问题,至少需要安装这4个主要依赖:

  • Xcode Command Line Tools
  • pixman
  • cairo
  • pango
正在检查 Disqus 能否访问...

Powered by  & DisqusJS


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK