31

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

> sharp@0.21.3 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 server@1.0.0 No description
npm WARN server@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.21.3 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.21.3 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.

Sunit Gautam
  • 5,495
  • 2
  • 18
  • 31
Florian Ludewig
  • 4,338
  • 11
  • 71
  • 137

24 Answers24

37

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

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

Usama Tahir
  • 1,707
  • 3
  • 15
  • 30
  • 1
    I also found [this blogpost](https://geedew.com/What-does-unsafe-perm-in-npm-actually-do/) 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 01 '20 at 17:30
13

That actually helped me, using node 14.20.1

npm install sharp --ignore-scripts
Mohamed Ali
  • 131
  • 1
  • 4
11

The simplest way is:

brew uninstall vips

And then:

npm install
Jim
  • 259
  • 3
  • 7
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
crg
  • 4,284
  • 2
  • 29
  • 57
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

tejas n
  • 638
  • 1
  • 8
  • 14
7

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

npm install sharp@0.23.2 

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

Trinh Hieu
  • 379
  • 3
  • 6
6

delete package-lock.json and node_modules

then try to install packages npm install

Worked for me.

Dileep XDN
  • 151
  • 2
  • 3
4

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

Farad
  • 885
  • 2
  • 9
  • 25
3

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.

Muhamet Smaili
  • 375
  • 2
  • 9
3

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

yarn add sharp
BeardOverflow
  • 938
  • 12
  • 15
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

justadev
  • 1,168
  • 1
  • 17
  • 32
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
Muhammad Umar
  • 1,291
  • 7
  • 13
  • 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. – Orion Cygnus Dec 10 '21 at 10:58
  • I'm glad if it helped. I faced the issue in NodeJs(Javascript) – Muhammad Umar Dec 10 '21 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

Jayja
  • 29
  • 5
1

macOS should install the vips package first

brew install vips
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Felix
  • 11
  • 1
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.

CY Mak
  • 1
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
Jagaa
  • 531
  • 7
  • 15
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
Edie Lemoine
  • 169
  • 2
  • 8
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

Al Mamun Khan
  • 551
  • 6
  • 7
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
leettamna
  • 1
  • 1
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

anville95
  • 21
  • 5
0

Using Pnpm; on M1 Mac, this helped:

pnpm install sharp --config.arch=x64 --config.platform=linux
Ahmad Ali
  • 704
  • 1
  • 10
  • 28
-3
npm install --unsafe-perm -g cordova-res
cottontail
  • 10,268
  • 18
  • 50
  • 51