在 linux 中安装 cordova-res 和 sharp 包时 sharp 安装失败 (npm)

sharp installation failed (npm) while installing cordova-res and sharp packages in linux

我已经在 ubuntu 20.04 和 debian buster 中安装了最新版本的 node 和 npm。 我已经从 linux

中的 apt 安装了 libvips 和 glib 软件包
/usr/include/vips/vips8:35:10: fatal error: glib-object.h: No such file or directory
 #include <glib-object.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
make: *** [sharp.target.mk:129: Release/obj.target/sharp/src/common.o] Error 1
make: Leaving directory '/usr/local/lib/node_modules/cordova-res/node_modules/sharp/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 5.4.0-42-lowlatency
gyp ERR! command "/usr/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/cordova-res/node_modules/sharp
gyp ERR! node -v v10.21.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.25.4 install: `(node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sharp@0.25.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!     /root/.npm/_logs/2020-07-25T14_48_56_334Z-debug.log

有知道的请回答。如何将glib-object.h添加到vips目录?

现在已通过更改所需版本(支持旧的 nodejs 版本)来修复它。使用 nvm 您可以轻松地在版本之间切换而无需卸载当前版本。 节点中的许多包,不支持最新(最新)版本。所以你必须迁移到旧版本。 即使它无法通过包管理器(npm)安装 prebuild

  1. brew 安装 pkg-config

  2. 现在你需要从源码安装 libvips

  3. https://github.com/libvips/libvips/releases

    下载并解压最新版本
  4. cd 到解压文件夹

  5. ./configure

  6. 制作

  7. sudo make install

  8. npm i -g cordova-res