Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't install Sharp

Tags:

node.js

npm

sharp

When running sudo npm i sharp --save I get the following errors:

> [email protected] install /home/server/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Using cached /home/ronny/.npm/_libvips/libvips-8.7.0-linux-x64.tar.gz
ERR! sharp EACCES: permission denied, mkdir '/home/server/node_modules/sharp/vendor'
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/page/install for required dependencies
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/server/node_modules/sharp/build'
gyp ERR! System Linux 4.18.0-13-generic
gyp ERR! command "/usr/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/server/node_modules/sharp
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] 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 [email protected] 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!     /home/ronny/.npm/_logs/2019-01-28T20_33_46_476Z-debug.log

I have the same project running on another machine, and there, the install works flawlessly. But on my other machine (both run Linux Ubuntu) I am facing the above error.

I couldn't find any solution for this error. That's why I am asking for help here.

like image 516
Flo Avatar asked Jan 28 '19 20:01

Flo


People also ask

What is sharp in npm?

The typical use case for this high speed Node. js module is to convert large images in common formats to smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.

What is sharp in node js?

sharp is a popular Node. js image processing library that supports various image file formats, such as JPEG, PNG, GIF, WebP, AVIF, SVG and TIFF. In this tutorial, you'll use sharp to read an image and extract its metadata, resize, change an image format, and compress an image.

How do you use Nextjs sharp?

You simply install sharp , Next. js will use it in production mode if installed. No need to import it anywhere in your codebase.


3 Answers

this worked for me. npm install --unsafe-perm

please refer to the following discussion https://github.com/lovell/sharp/issues/1627#issuecomment-477109851

like image 68
Usama Tahir Avatar answered Oct 18 '22 02:10

Usama Tahir


The simplest way is:

brew uninstall vips

And then:

npm install
like image 21
Jim Avatar answered Oct 18 '22 02:10

Jim


For Apple M1 brew install vips then npm install --unsafe-perm

If it does not solved your problem find more in this similar issue

  • xcode-select --install
  • brew install gcc
  • brew reinstall vips
  • brew info vips
  • npm i
like image 6
crg Avatar answered Oct 18 '22 02:10

crg