npm安裝sharp出現(xiàn)的問(wèn)題詳解(安裝失敗的問(wèn)題及解決)
npm安裝sharp庫(kù)出現(xiàn)的問(wèn)題及解決 npm安裝sharp出現(xiàn)的問(wèn)題及解決:
Buffer的使用以及對(duì)圖片的操作(通過(guò)sharp庫(kù)對(duì)圖片進(jìn)行操作)
npm安裝sharp出現(xiàn)的問(wèn)題及解決:

- 在使用npm安裝sharp一直安裝不成功。后面發(fā)現(xiàn)安裝sharp需要依賴(lài)libvips,然后通過(guò)查看npm路徑下的_libvips文件夾確實(shí)為空。(可通過(guò)npm config get cache查詢(xún)自己的npm存放路徑)
- 后面嘗試自己下載libvips的安裝包,然后在進(jìn)行安裝,發(fā)現(xiàn)也還是不行。
- 最后我是通過(guò)修改鏡像終于安裝成功。
- 使用鏡像地址(僅設(shè)置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 的封裝,所以在安裝的時(shí)候會(huì)去下載 libvips 的本體,所以最好提前配置好鏡像源。

在使用npm安裝sharp的時(shí)候,需要注意以下問(wèn)題
- 使用鏡像地址:
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某版本號(hào)對(duì)應(yīng)的libvips依賴(lài)包,放在npm的緩存路徑中,通常這個(gè)路徑是
/Users/<username>/.npm/_libvips(在使用了nvm管理node版本的情況下)
如果沒(méi)有提前下載好并放在緩存中,可能會(huì)出現(xiàn)如下的報(bào)錯(cuò)信息
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總結(jié)
到此這篇關(guān)于npm安裝sharp出現(xiàn)的問(wèn)題(安裝失敗的問(wèn)題及解決)的文章就介紹到這了,更多相關(guān)npm安裝sharp問(wèn)題內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
idea無(wú)法使用nodejs的幾個(gè)原因及解決辦法
這篇文章主要給大家介紹了關(guān)于idea無(wú)法使用nodejs的幾個(gè)原因及解決辦法,包括安裝檢查、環(huán)境變量配置、IDEA路徑設(shè)置、終端問(wèn)題排查、緩存清理、權(quán)限調(diào)整、安全軟件干擾、依賴(lài)安裝及日志分析,需要的朋友可以參考下2025-05-05
node.js讀取Excel數(shù)據(jù)(下載圖片)的方法示例
這篇文章主要給大家介紹了關(guān)于node.js讀取Excel數(shù)據(jù)(下載圖片)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用node.js具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08
nodejs前端自動(dòng)化構(gòu)建環(huán)境的搭建
本文這里給大家介紹的是nodejs中前端自動(dòng)化構(gòu)建環(huán)境的搭建方法,非常的細(xì)致全面,有需要的小伙伴可以參考下2017-07-07
node.js中的fs.createReadStream方法使用說(shuō)明
這篇文章主要介紹了node.js中的fs.createReadStream方法使用說(shuō)明,本文介紹了fs.createReadStream方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12
HTTP JSON接口模擬工具Interfake快速入門(mén)教程
這篇文章主要為大家介紹了HTTP JSON接口模擬工具Interfake快速入門(mén)教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06

