32

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 s[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.

2
  • gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/server/node_modules/sharp/build' (SUDO?) Jan 28, 2019 at 20:50
  • I entered the command with sudo, so I should have permission Jan 29, 2019 at 15:23

25 Answers 25

37

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

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

2
  • 1
    I also found this blogpost helpful to understand the reasons for this. Simply put, npm tries to switch to a user account when installing modules, as modules installed as root can be only used by a root process. It is considered unsafe to run regular processes as root, hence the parameter name.
    – drali
    Nov 1, 2020 at 17:30
  • To make this work for me, I use the following command: 'pnpm install --ignore-scripts=false --verbose sharp'
    – Frank Guo
    Nov 25 at 14:32
16

That actually helped me, using node 14.20.1

npm install sharp --ignore-scripts
0
14

The simplest way is:

brew uninstall vips

And then:

npm install
1
  • 2
    Can we shed some light as to why this works, please? Why the upvotes?
    – philipjc
    Apr 27 at 11:02
9

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
8

npm install --arch=x64 --platform=linux sharp worked for me

taken from : https://github.com/lovell/sharp/issues/2128#issuecomment-600232917

I am using a M1 mac

7

The problem with Node v13.14.0+, the problem will be solved

npm install [email protected] 

You should downgrade Node version to >=10.0.0 if you are using sharp 0.22.1

2
  • Problem persists in version 0.28.3
    – Mild Fuzz
    Sep 7, 2022 at 18:20
  • You need to downgrade Sharp or Nodejs version. You need to check compatibility because higher versions often cause conflicts
    – Trinh Hieu
    Jun 8 at 7:47
4

I have solved this error by downgrading node version to 10.0.0. It really works!

1
  • In my case downgrading from v16.13.0 to v14.16.1 solves the problem
    – andrew
    Nov 24, 2021 at 15:55
4

delete package-lock.json and node_modules

then try to install packages npm install

Worked for me.

1
  • it work for me, my node version v14.17.0 npm version 7.17.0 sharp version "^0.27.0"
    – asraful009
    Jun 15, 2021 at 7:24
3

Try yarn instead of npm, it works for me (docker, official node image 16.x)

yarn add sharp
2

So first the error says Permission denied. install it using
sudo
when you use sudo in the sharp documentation! it says that you have to use
npm install --unsafe-perm

I would recommend:

  • go to /home/ronny/.npm/_libvips/libvips-8.7.0-linux-x64.tar.gz (in your error code)
  • remove the file: libvips-8.7.0-linux-x64.tar.gz
  • in your terminal type: npm install --unsafe-perm (this will install the deleted lib)
  • npm install sharp

Then I think I should work fine. These steps fixed my issue, I had the same issue. Hope it helps. Thanks.

2

I had the same problem for my Apple M1 and I ran the next comands:

  • I removed node_modules
  • I deleted package-lock.json
  • Run: brew install vips
  • Run: npm install --unsafe-perm

And it works

2

I had this issue as well. I installed the required (6Gb!!) Visual Studio 2022 Build tools, but even after reboot it was still not working.

Another thing I tried was setting the following:

npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe"

still didn't work.

Finally, I deleted node_modules and package-lock.json. I deleted the sharp module from package.json and install everything.

Then I run:

npm install sharp --save

And finally it worked

1

Late but I'm telling you what worked for me. If you have previously installed any dependency that works exactly the same as sharp, remove that dependency from your Package.json file and then run

npm install sharp
2
  • I faced a problem with sharp on multiple OS/distros as I started working on a project about 3 years old. This solution solved my problem on MacOS BigSur, Windows 11 and CentOS 7.9. And a side note, this problem might be caused by missing python 3. Dec 10, 2021 at 10:58
  • I'm glad if it helped. I faced the issue in NodeJs(Javascript) Dec 10, 2021 at 13:02
1

npm install --platform=darwin --arch=x64 sharp

https://sharp.pixelplumbing.com/install

I'm using a Macbook pro M1 nodeJS version v16.14.2 It works for me

1

macOS should install the vips package first

brew install vips
0

Running npx create-strapi-app my-project --quickstart on windows and got the same error, had to install C++ for desktop development from visual studio and it worked.

0

In my case, I had to install Python first. After that, it went well. Install Python here.

npm i sharp
npm ERR! code 1
npm ERR! gyp ERR! find Python
gyp ERR! stack     at PythonFinder
0

One other thing you can try is to open up task manager and kill node js process that is currently running

0

For me, reading the logs helped me find a solution.

Yarn output:

➤ YN0009: │ sharp@npm:0.30.7 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/yc/78ts3g2s4mxdbxsln5kz16dm0000gn/T/xfs-49e52cab/build.log)

And in that log file I noticed this line:

env: python: No such file or directory

I only had a python3 binary, no python, so I symlinked python3 to /usr/local/bin/python, which allowed me to install sharp.

ln -sf $(which python3) /usr/local/bin/python
1
  • i ran across a syntax error using this apprach. I think actually using python2 for python makes more sense Dec 17, 2022 at 23:30
0

Linux/Ubuntu: I face the issue.error node version 18.12.1, but first try to install node-gyp

  • sudo npm install -g node-gyp

then remove old package-lock.json and again try to install

  • npm i sharp this time it's work, than again install all the package
  • npm install success

note: if you not fixed it. Please check out sharp-installation guide

0

I add one command before 'npm install' executed.

- USER=`whoami` && sudo chown $USER:$USER .
- npm install --verbose

# node => 16
# npm => 8.11.0
# sharp => 0.31.3
1
  • I thought I'm solved. But It was not
    – leettamna
    Jan 17 at 8:30
0

I had a similar issue and I found a very good solution. If you use unsafe perm, the module will get installed but might not work when you try to use it, none of mine did. The solution is to install the latest version of node js. The default ubuntu repository does not offer the latest version unfortunately thus one needs to add the node js repository with the latest node js version. To do this, curl is required.

First remove the currently installed node js

sudo apt remove node js

Also remove the currently installed npm

sudo apt remove npm

Curl is installed with the advanced package tool as follows:

sudo apt-get install curl

After installing curl, now the good node js repository may be added as follows:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

Now the latest version of node js may be installed with the advanced package tool

sudo apt-get install nodejs

Checking the node js version, you'll get version >= 18

node -v

Also checking the npm version

npm -v

Now one may proceed to install the module and it will work perfectly. In my case it was sharp

sudo npm install sharp

I got my solution here. Thank you for reading, happy coding

0

Using Pnpm; on M1 Mac, this helped:

pnpm install sharp --config.arch=x64 --config.platform=linux
0

For me, this issue occurred on an M1 Mac.

What worked:

$ brew uninstall vips # I believe this makes sharp use the version $ it's compatible with
$ yarn install sharp@next

I am on a react-native project. Node version: v18.17.0

-3
npm install --unsafe-perm -g cordova-res
1
  • 1
    What does Cordova have to do with this? Oct 10, 2022 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.