npm安裝sharp出現(xiàn)的問題詳解(安裝失敗的問題及解決)
npm安裝sharp庫出現(xiàn)的問題及解決 npm安裝sharp出現(xiàn)的問題及解決:
Buffer的使用以及對圖片的操作(通過sharp庫對圖片進(jìn)行操作)
npm安裝sharp出現(xiàn)的問題及解決:
- 在使用npm安裝sharp一直安裝不成功。后面發(fā)現(xiàn)安裝sharp需要依賴libvips,然后通過查看npm路徑下的_libvips文件夾確實(shí)為空。(可通過npm config get cache查詢自己的npm存放路徑)
- 后面嘗試自己下載libvips的安裝包,然后在進(jìn)行安裝,發(fā)現(xiàn)也還是不行。
- 最后我是通過修改鏡像終于安裝成功。
- 使用鏡像地址(僅設(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 的封裝,所以在安裝的時候會去下載 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某版本號對應(yīng)的libvips依賴包,放在npm的緩存路徑中,通常這個路徑是
/Users/<username>/.npm/_libvips
(在使用了nvm管理node版本的情況下)
如果沒有提前下載好并放在緩存中,可能會出現(xiàn)如下的報錯信息
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)的問題(安裝失敗的問題及解決)的文章就介紹到這了,更多相關(guān)npm安裝sharp問題內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在windows上用nodejs搭建靜態(tài)文件服務(wù)器的簡單方法
這篇文章主要介紹了在windows上用nodejs搭建靜態(tài)文件服務(wù)器的簡單方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08Express中使用Swagger的實(shí)現(xiàn)示例
swagger-express是一個規(guī)范和完整的框架實(shí)現(xiàn),本文主要介紹了Express中使用Swagger的實(shí)現(xiàn)示例,具有一定的參考價值,感興趣的可以了解一下2023-12-12Koa2中間件的作用及路由實(shí)現(xiàn)實(shí)例詳解
這篇文章主要介紹了Koa2中間件的作用及路由實(shí)現(xiàn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05Node.js和MongoDB實(shí)現(xiàn)簡單日志分析系統(tǒng)
這篇文章主要介紹了Node.js和MongoDB實(shí)現(xiàn)簡單日志分析系統(tǒng),本文給出了服務(wù)器端、客戶端、圖表生成、Shell自動執(zhí)行等功能的實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-04-04