Gatsby: Something went wrong installing the "sharp" module

Created on 28 May 2020  ยท  4Comments  ยท  Source: gatsbyjs/gatsby

Description

gatsby develop fails on existing site or even a new build.

Full error below:

Error in "/Users/hsnyc/Documents/Hosts/hsnyc/hsnyc_v4/hsnyc-gatsby/node_modules/gatsby-transformer-sharp/gatsby-node.js":
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp.node'

- Run "npm rebuild --verbose sharp" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/install
- Search for this error at https://github.com/lovell/sharp/issues

  Error: Something went wrong installing the "sharp" module
  Cannot find module '../build/Release/sharp.node'
  - Run "npm rebuild --verbose sharp" and look for errors
  - Consult the installation documentation at https://sharp.pixelplumbing.com/  install
  - Search for this error at https://github.com/lovell/sharp/issues

  - constructor.js:34 Object.<anonymous>
    [hsnyc-gatsby]/[sharp]/lib/constructor.js:34:9

  - v8-compile-cache.js:178 Module._compile
    [hsnyc-gatsby]/[v8-compile-cache]/v8-compile-cache.js:178:30

  - loader.js:789 Object.Module._extensions..js
    internal/modules/cjs/loader.js:789:10

  - loader.js:653 Module.load
    internal/modules/cjs/loader.js:653:32

  - loader.js:593 tryModuleLoad
    internal/modules/cjs/loader.js:593:12

  - loader.js:585 Function.Module._load
    internal/modules/cjs/loader.js:585:3

  - loader.js:692 Module.require
    internal/modules/cjs/loader.js:692:17

  - v8-compile-cache.js:159 require
    [hsnyc-gatsby]/[v8-compile-cache]/v8-compile-cache.js:159:20

  - index.js:3 Object.<anonymous>
    [hsnyc-gatsby]/[sharp]/lib/index.js:3:15

  - v8-compile-cache.js:178 Module._compile
    [hsnyc-gatsby]/[v8-compile-cache]/v8-compile-cache.js:178:30

  - loader.js:789 Object.Module._extensions..js
    internal/modules/cjs/loader.js:789:10

  - loader.js:653 Module.load
    internal/modules/cjs/loader.js:653:32

  - loader.js:593 tryModuleLoad
    internal/modules/cjs/loader.js:593:12

  - loader.js:585 Function.Module._load
    internal/modules/cjs/loader.js:585:3

  - loader.js:692 Module.require
    internal/modules/cjs/loader.js:692:17

  - v8-compile-cache.js:159 require
    [hsnyc-gatsby]/[v8-compile-cache]/v8-compile-cache.js:159:20


not finished load plugins - 0.330s

Steps to reproduce

Had node 8 installed when I first noticed the error. Upgraded to 12, cleared npm cache npm cache clear and gatsby cache gatsby clean. Rebuild npm rebuild --verbose sharp no errors.
Downgraded to Node 10 and repeated the above steps. Same error.

Expected result

To have the local server run.

Actual result

Sharp error

Environment

System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.18.0 - /usr/local/bin/node
npm: 6.13.4 - /usr/local/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 83.0.4103.61
Firefox: 57.0.4
Safari: 13.1
npmPackages:
gatsby: ^2.21.37 => 2.21.37
gatsby-image: ^2.4.4 => 2.4.4
gatsby-plugin-manifest: ^2.4.5 => 2.4.5
gatsby-plugin-offline: ^3.2.3 => 3.2.3
gatsby-plugin-react-helmet: ^3.3.1 => 3.3.1
gatsby-plugin-sharp: ^2.6.4 => 2.6.4
gatsby-source-filesystem: ^2.3.4 => 2.3.4
gatsby-transformer-sharp: ^2.5.2 => 2.5.2
npmGlobalPackages:
gatsby-cli: 2.12.36

sharp

Most helpful comment

For me, the problem is about the node's version. I use nvm and tested with three versions:

14.14.0
12.19.0
10.22.1

Only 10.22.1 works for me. I recommend using the nvm (Node Version Manager) to deal with this.

All 4 comments

Are you able to share your project so we can try to reproduce? Can you try running npm ls sharp? Also output of npm rebuild --verbose sharp could be helpful.

Hi. Sure. Here is the output for those:

Henrys-MBP-2:hsnyc-gatsby hsnyc$ npm ls sharp
[email protected] /Users/hsnyc/Documents/Hosts/hsnyc/hsnyc_v4/hsnyc-gatsby
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]  deduped
โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”€ [email protected]  deduped
Henrys-MBP-2:hsnyc-gatsby hsnyc$ npm rebuild --verbose sharp
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'rebuild',
npm verb cli   '--verbose',
npm verb cli   'sharp' ]
npm info using [email protected]
npm info using [email protected]
npm info readInstalled object
npm verb rebuild path, id [ '/Users/hsnyc/Documents/Hosts/hsnyc/hsnyc_v4/hsnyc-gatsby/node_modules/sharp',
npm verb rebuild   '[email protected]' ]
npm info build /Users/hsnyc/Documents/Hosts/hsnyc/hsnyc_v4/hsnyc-gatsby/node_modules/sharp
npm info lifecycle [email protected]~preinstall: [email protected]
npm info linkStuff [email protected]
npm verb rebuildBundles [ '.bin', 'semver' ]
npm info lifecycle [email protected]~install: [email protected]
npm info lifecycle [email protected]~install: ignored because ignore-scripts is set to true [email protected]
npm info lifecycle [email protected]~postinstall: [email protected]
[email protected] /Users/hsnyc/Documents/Hosts/hsnyc/hsnyc_v4/hsnyc-gatsby/node_modules/sharp
npm verb exit [ 0, true ]
npm timing npm Completed in 3606ms
npm info ok

I have made a repo here with the files. Thanks for your help.

Well after various attempts to resolve I finally found a solution.

Here is how I was able to get it to work (Using a MAC):

  1. Completely uninstall Node and NPM by following the steps in this post.
  2. Install Node again using nvm - Here is how.
  3. On the existing project, delete node_modules and package-lock.json file. Run npm install.
  4. On new project works fine.

For me, the problem is about the node's version. I use nvm and tested with three versions:

14.14.0
12.19.0
10.22.1

Only 10.22.1 works for me. I recommend using the nvm (Node Version Manager) to deal with this.

Was this page helpful?
0 / 5 - 0 ratings