npm安装sharp出现的问题详解(安装失败的问题及解决)

 更新时间:2023年11月07日 09:16:53   作者:fifih  
这篇文章主要给大家介绍了关于npm安装sharp出现的问题(安装失败的问题及解决)的相关资料,sharp包是基于node.js的高性能图片处理器,文中通过代码介绍的非常详细,需要的朋友可以参考下

npm安装sharp库出现的问题及解决 npm安装sharp出现的问题及解决:

Buffer的使用以及对图片的操作(通过sharp库对图片进行操作)

npm安装sharp出现的问题及解决:

安装失败的报错

  • 在使用npm安装sharp一直安装不成功。后面发现安装sharp需要依赖libvips,然后通过查看npm路径下的_libvips文件夹确实为空。(可通过npm config get cache查询自己的npm存放路径)
  • 后面尝试自己下载libvips的安装包,然后在进行安装,发现也还是不行。
  • 最后我是通过修改镜像终于安装成功。
  • 使用镜像地址(仅设置sharp):
npm config set sharp_binary_host "https://npmmirror.com/mirrors/sharp"
npm config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"

sharp 是基于 libvips 的封装,所以在安装的时候会去下载 libvips 的本体,所以最好提前配置好镜像源。

安装成功截图

在使用npm安装sharp的时候,需要注意以下问题

  • 使用镜像地址:
npm config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
npm config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
  • 提前下载好sharp某版本号对应的libvips依赖包,放在npm的缓存路径中,通常这个路径是/Users/<username>/.npm/_libvips(在使用了nvm管理node版本的情况下)

如果没有提前下载好并放在缓存中,可能会出现如下的报错信息

info sharp Using cached /Users/<usernmae>/.npm/_libvips/libvips-8.10.0-darwin-x64.tar.br
ERR! sharp Decompression failed
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/install for required dependencies
  TOUCH Release/obj.target/libvips-cpp.stamp
  CC(target) Release/obj.target/nothing/node_modules/node-addon-api/nothing.o
  LIBTOOL-STATIC Release/nothing.a
  CXX(target) Release/obj.target/sharp/src/common.o
../src/common.cc:24:10: fatal error: 'vips/vips8' file not found
#include <vips/vips8>
         ^~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/sharp/src/common.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/maxingyuan/.nvm/versions/node/v12.16.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 19.6.0
gyp ERR! command "/Users/<usernmae>/.nvm/versions/node/v12.16.1/bin/node" "/Users/<usernmae>/.nvm/versions/node/v12.16.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/maxingyuan/.nvm/versions/node/v12.16.1/lib/node_modules/sharp
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.26.2 install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sharp@0.26.2 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/<usernmae>/.npm/_logs/2020-11-11T07_51_13_893Z-debug.log

总结

到此这篇关于npm安装sharp出现的问题(安装失败的问题及解决)的文章就介绍到这了,更多相关npm安装sharp问题内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • idea无法使用nodejs的几个原因及解决办法

    idea无法使用nodejs的几个原因及解决办法

    这篇文章主要给大家介绍了关于idea无法使用nodejs的几个原因及解决办法,包括安装检查、环境变量配置、IDEA路径设置、终端问题排查、缓存清理、权限调整、安全软件干扰、依赖安装及日志分析,需要的朋友可以参考下
    2025-05-05
  • node.js快速部署vue代码详细步骤

    node.js快速部署vue代码详细步骤

    众所周知Vue是现在前端最流行的框架之一,作为前端开发人员应该要熟练的掌握它,下面这篇文章主要给大家介绍了关于node.js快速部署vue代码的详细步骤,文中通过示例代码介绍的非常详细,需要的朋友可以参考下
    2023-05-05
  • node.js读取Excel数据(下载图片)的方法示例

    node.js读取Excel数据(下载图片)的方法示例

    这篇文章主要给大家介绍了关于node.js读取Excel数据(下载图片)的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用node.js具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-08-08
  • Node.js中的进程间通信

    Node.js中的进程间通信

    这篇文章主要介绍了Node.js中的进程间通信,文章围绕主题展开详细的内容戒杀,具有一定的参考价值,感兴趣的小伙伴可以参考一下
    2022-09-09
  • 用Node写一条配置环境的指令

    用Node写一条配置环境的指令

    这篇文章主要介绍了用Node写一条配置环境的指令,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11
  • nodejs前端自动化构建环境的搭建

    nodejs前端自动化构建环境的搭建

    本文这里给大家介绍的是nodejs中前端自动化构建环境的搭建方法,非常的细致全面,有需要的小伙伴可以参考下
    2017-07-07
  • node.js中的fs.createReadStream方法使用说明

    node.js中的fs.createReadStream方法使用说明

    这篇文章主要介绍了node.js中的fs.createReadStream方法使用说明,本文介绍了fs.createReadStream方法说明、语法、接收参数、使用实例和实现源码,需要的朋友可以参考下
    2014-12-12
  • HTTP JSON接口模拟工具Interfake快速入门教程

    HTTP JSON接口模拟工具Interfake快速入门教程

    这篇文章主要为大家介绍了HTTP JSON接口模拟工具Interfake快速入门教程,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-06-06
  • node中使用shell脚本的方法步骤

    node中使用shell脚本的方法步骤

    这篇文章主要介绍了node中使用shell脚本的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-03-03
  • 浅谈node的事件机制

    浅谈node的事件机制

    本篇文章主要介绍了node的事件机制,本文通过实现一个简易的、具有发布/订阅模式的事件机制,以此来理清EventEmitter类的实现思路,有兴趣的可以了解一下
    2017-10-10

最新评论