Gatsby: Unable to install gatsby-plugin-sharp

Created on 23 Sep 2019  ·  15Comments  ·  Source: gatsbyjs/gatsby

Description

I'm unable to install gatsby-plugin-sharp in Ubuntu 18.04. I've been working on a project that has been using gatsby-plugin-sharp as a dependency for weeks with no problem, until this morning.

Here's a snippet of my package.json:

{
  "dependencies": {
    "gatsby-plugin-sharp": "^2.2.20",
    "gatsby-transformer-sharp":` "^2.2.13"
  }
}

Steps to reproduce

gatsby new gatsby-starter-hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world
cd gatsby-starter-hello-world
npm install --save gatsby-plugin-sharp

Expected result

Should be able to install with no errors.

Actual result

yarn add v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "gatsby > [email protected]" has incorrect peer dependency "[email protected]".
warning "gatsby > @typescript-eslint/eslint-plugin > [email protected]" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] Building fresh packages...
[-/7] ⠁ waiting...
[7/7] ⠁ sharp
[-/7] ⠁ waiting...
[-/7] ⠁ waiting...
error /home/sean/Documents/gatsby-starter-hello-world/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
Arguments: 
Directory: /home/sean/Documents/gatsby-starter-hello-world/node_modules/sharp
Output:
info sharp Using cached /home/sean/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz
prebuild-install WARN install libvips-cpp.so.42: cannot open shared object file: No such file or directory
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info spawn /usr/bin/python2.7
gyp info spawn args [ '/home/sean/.nvm/versions/node/v8.16.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/sean/Documents/gatsby-starter-hello-world/node_modules/sharp/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/sean/.nvm/versions/node/v8.16.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/sean/.node-gyp/8.16.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/sean/.node-gyp/8.16.1',
gyp info spawn args   '-Dnode_gyp_dir=/home/sean/.nvm/versions/node/v8.16.1/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/home/sean/.node-gyp/8.16.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/home/sean/Documents/gatsby-starter-hello-world/node_modules/sharp',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/sean/Documents/gatsby-starter-hello-world/node_modules/sharp/build'
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
../src/common.cc:25:10: fatal error: vips/vips8: No such file or directory
 #include <vips/vips8>
          ^~~~~~~~~~~~
compilation terminated.
sharp.target.mk:127: recipe for target 'Release/obj.target/sharp/src/common.o' failed
make: *** [Release/obj.target/sharp/src/common.o] Error 1
make: Leaving directory '/home/sean/Documents/gatsby-starter-hello-world/node_modules/sharp/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/sean/.nvm/versions/node/v8.16.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 4.15.0-62-generic
gyp ERR! command "/home/sean/.nvm/versions/node/v8.16.1/bin/node" "/home/sean/.nvm/versions/node/v8.16.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/sean/Documents/gatsby-starter-hello-world/node_modules/sharp
gyp ERR! node -v v8.16.1

Environment

  System:
    OS: Linux 4.15 Ubuntu 18.04.3 LTS (Bionic Beaver)
    CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 8.16.1 - ~/.nvm/versions/node/v8.16.1/bin/node
    Yarn: 1.17.3 - /usr/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v8.16.1/bin/npm
  Languages:
    Python: 3.7.3 - /home/sean/anaconda3/bin/python
  Browsers:
    Chrome: 76.0.3809.100
    Firefox: 69.0
  npmPackages:
    gatsby: ^2.13.73 => 2.15.21
    gatsby-background-image: ^0.8.9 => 0.8.12
    gatsby-image: ^2.2.14 => 2.2.20
    gatsby-plugin-catch-links: ^2.1.5 => 2.1.10
    gatsby-plugin-netlify: ^2.1.15 => 2.1.15
    gatsby-plugin-netlify-cache: ^1.2.0 => 1.2.0
    gatsby-plugin-netlify-cms: ^4.1.13 => 4.1.18
    gatsby-plugin-react-helmet: ^3.1.5 => 3.1.8
    gatsby-plugin-sass: ^2.1.12 => 2.1.15
    gatsby-plugin-sitemap: ^2.2.9 => 2.2.14
    gatsby-source-filesystem: ^2.1.16 => 2.1.26
    gatsby-transformer-remark: ^2.6.19 => 2.6.24

Most helpful comment

@gpspake I'm having this issue as well, were you able to fix it?

**I fixed it after upgrading Gatsby and deleting node_modules and the lockfile.

All 15 comments

I'm experiencing the same issue with Node 10, 11, and 12. Was working this morning for me, until I tried to reload my dependencies.

  System:
    OS: macOS 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
    Shell: 3.0.2 - /usr/local/bin/fish
  Binaries:
    Node: 11.15.0 - ~/.nvm/versions/node/v11.15.0/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.15.0/bin/npm
  Languages:
    Python: 2.7.16 - /usr/local/bin/python
  Browsers:
    Chrome: 76.0.3809.132
    Safari: 12.1.2

There is an issue open on the sharp repo

This issue seems to be related to sharp and is being tracked at https://github.com/lovell/sharp/issues/1882.

FWIW I was watching this issue and the issue in the lovell/sharp repo, and the problem seems to have been resolved for me in Gatsby land just in the last 15 minutes. I'm using npm and npm installing in my Gatsby repo, and it's no longer exiting with a failure due to the missing vips file, so I'm back in business 👍

@foxdoubt Are you putting

  "resolutions": {
    "minipass": "2.7.0"
  }

in your package.json? That's the only way I'm able to get it to work right now.

@swkeever I installed another project with gatsby new <site-name>, confirmed that the install made it through the sharp installation part, and when I navigated back to my original site repo and npm installed again, the problem had been resolved. I guess it's possible that the fresh install with gatsby new did something.

but no, not using "resolutions" in package.json

I had same issue when having new project with gatsby.
You can just make sure you remove node modules rm -rf node_modules/ inside your project,
then sudo npm install --unsafe-perm instead of using npm install only.

update: I tried replacing dependencies with the ones in working new project, clearing cache, deleting node_modules, deleting lock, and running yarn install. When that worked, I added my dependencies back and repeated with no issues.


I'm still having this issue on OSX using Yarn. I pulled down a gatsby project that was last updated and working fine just a month or so ago and I can't run yarn install without it blowing up:

error /Users/georgespake/code/devmemphis/website/node_modules/favicons/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
Arguments:
Directory: /Users/georgespake/code/devmemphis/website/node_modules/favicons/node_modules/sharp
Output:
info sharp Using cached /Users/georgespake/.npm/_libvips/libvips-8.7.4-darwin-x64.tar.gz
prebuild-install WARN install No prebuilt binaries found (target=13.7.0 runtime=node arch=x64 libc= platform=darwin)
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info find Python using Python version 2.7.16 found at "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python"
gyp info spawn /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
gyp info spawn args [
gyp info spawn args   '/usr/local/Cellar/node/13.7.0/libexec/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/georgespake/code/devmemphis/website/node_modules/favicons/node_modules/sharp/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/Cellar/node/13.7.0/libexec/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/georgespake/Library/Caches/node-gyp/13.7.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/georgespake/Library/Caches/node-gyp/13.7.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/Cellar/node/13.7.0/libexec/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/georgespake/Library/Caches/node-gyp/13.7.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/georgespake/code/devmemphis/website/node_modules/favicons/node_modules/sharp',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
  CXX(target) Release/obj.target/sharp/src/metadata.o
  CXX(target) Release/obj.target/sharp/src/stats.o
../src/stats.cc:130:19: error: no matching member function for call to 'Set'
        channels->Set(i, channelStat);
        ~~~~~~~~~~^~~
/Users/georgespake/Library/Caches/node-gyp/13.7.0/include/node/v8.h:3547:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                    ^
/Users/georgespake/Library/Caches/node-gyp/13.7.0/include/node/v8.h:3550:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,

I've tried all of the solutions above as well as deleting node modules, deleting yarn.lock, creating a new gatsby project (which worked) and copying all the dependencies from the latest package json over, and re-running yarn install. I also followed the advice to brew install vips but so far nothing has worked for me.
package.json

{
  "name": "devmemphis",
  "private": true,
  "description": "A meetup for Memphis Software Developers",
  "version": "0.1.0",
  "author": "George Spake <[email protected]>",
  "bugs": {
    "url": "https://github.com/devmemphis/website/issues"
  },
  "dependencies": {
    "gatsby": "^2.18.12",
    "gatsby-image": "^2.2.34",
    "gatsby-plugin-favicon": "^3.1.6",
    "gatsby-plugin-feed": "^2.2.3",
    "gatsby-plugin-google-analytics": "^2.0.20",
    "gatsby-plugin-layout": "^1.0.15",
    "gatsby-plugin-manifest": "^2.2.31",
    "gatsby-plugin-offline": "^3.0.27",
    "gatsby-plugin-react-helmet": "^3.1.16",
    "gatsby-plugin-sass": "^2.0.11",
    "gatsby-plugin-sharp": "^2.3.5",
    "gatsby-plugin-typography": "^2.2.13",
    "gatsby-remark-copy-linked-files": "^2.0.13",
    "gatsby-remark-images": "^3.0.14",
    "gatsby-remark-prismjs": "^3.2.11",
    "gatsby-remark-responsive-iframe": "^2.1.1",
    "gatsby-remark-smartypants": "^2.0.9",
    "gatsby-source-filesystem": "^2.1.40",
    "gatsby-transformer-remark": "^2.3.12",
    "gatsby-transformer-sharp": "^2.3.7",
    "node-sass": "^4.12.0",
    "prismjs": "^1.16.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-helmet": "^5.2.1",
    "react-typography": "^0.16.19",
    "typeface-jaldi": "^0.0.71",
    "typeface-merriweather": "0.0.72",
    "typeface-montserrat": "0.0.54",
    "typeface-open-sans": "^0.0.54",
    "typeface-teko": "^0.0.72",
    "typography": "^0.16.19",
    "typography-theme-wordpress-2016": "^0.16.19"
  },
  "devDependencies": {
    "prettier": "^1.19.1"
  },
  "homepage": "https://devmemphis.org",
  "keywords": [
    "devmemphis, memtech"
  ],
  "license": "MIT",
  "main": "n/a",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/devmemphis/website.git"
  },
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "develop:windows": "gatsby develop -H 0.0.0.0",
    "format": "prettier --write src/**/*.{js,jsx}",
    "start": "npm run serve",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\""
  }
}

@gpspake I'm having this issue as well, were you able to fix it?

**I fixed it after upgrading Gatsby and deleting node_modules and the lockfile.

@erichodges how did you update gatsby?
I've been trying the whole week without success....

@flashimxd Hmmmm...I can't remember exactly. I'm usually using yarn, so I may have done:
$ yarn upgrade gatsby
You can read about it here:
https://classic.yarnpkg.com/en/docs/cli/upgrade/

Another way I have done it is to change the version in the package.json and then run the install again. You may need to delete the node_modules first though.

I think I did the yarn upgrade...

I had this error show up unexpectedly in an existing Gatsby site, after upgrading Node to a newer version.

Fixed this by deleting node_modules, deleting package-lock.json, and adding the resolutions code suggested by @swkeever above then re-running npm install. Thanks all for the comments here!

If you got here because you were trying to build inside a Docker container, it might be because you copied your local node_modules folder into the container as I did.

@peterwiebe I'm running into the same issue as you, but I don't believe I'm copying my local node_modules into the container. I have this as my .dockerignore; shouldn't Docker be ignoring my node_modules in this case?

.cache/
node_modules
**/node_modules
public/

And my Dockerfile:

RUN mkdir /app
WORKDIR /app

ENV PATH /app/node_modules/.bin:$PATH

ADD package.json yarn.lock /app/
RUN yarn
RUN yarn global add gatsby-cli

COPY . /app

EXPOSE 8000

CMD ["npm", "run", "develop"]

The develop npm script is "develop": "npm run clean && gatsby develop --port 8000",. Am I doing something wrong?

I ran into the same issue:

  • gatsby develop would throw an error (Something went wrong installing the "sharp" modul)
  • I deleted node_modules and tried to reinstall. Same issue
  • I deleted package.lock and tried to reinstall. Same issue

Then I figured out that I set my package manager to yarn but was trying to run npm install. 🤦 You can check the package manager you chose in ~/.config/gatsby/config.json.

What fixed the issue for me then was:

  • Upgrade yarn
  • Delete yarn.lock
  • Run yarn install
  • Run yarn add gatsby-cli
  • Run gatsby develop

Hope that helps someone

The problem in my case appeared to be mismatched version of hoisted prebuild-install. Installing gatsby-plugin-sharp and gatsby-transformer-sharp installs sharp which depends on prebuild-install, but multiple versions of prebuild-install end up hoisted, which causes an error.

I'm glad that I figured out the culprit (not the solution, though), because I was unable to install _any_ dependency because of this problem, and no amount of deleting node_modules and yarn.lock helped. 😕 After uninstalling these two plugins I was finally able to continue working.

Was this page helpful?
0 / 5 - 0 ratings