Sharp: Sharp Module Installation Error: Cannot find module - during Gatsby build

Created on 11 Jan 2020  Â·  6Comments  Â·  Source: lovell/sharp

Did you see the documentation relating to installation?
Yes

Have you ensured the platform and version of Node.js used for npm install is the same as the platform and version of Node.js used at runtime?
Turns out Ubuntu repositories were quite out of date, and I was on npm 3.5.2. Using this I was able to get it up to 6.13.6, but there is still a discrepancy compared to Node, which is on 8.10.0. I realize this could be an issue.

If you are installing as a root or sudo user, have you tried with the npm install --unsafe-perm flag?
I gave this a try, and the previous error about missing my GraphQL dependency has disappeared. It has not resolved the gatsby issue, however.

What is the complete output of running npm install --verbose sharp? Have you checked this output for useful error messages?
It looks like there are some minor optional dependency warnings, but no errors:

npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'install',
npm verb cli '--unsafe-perm',
npm verb cli '--verbose',
npm verb cli 'sharp' ]
npm info using [email protected]
npm info using [email protected]
npm verb npm-session 634ea073ccd922d9
npm http fetch GET 304 https://registry.npmjs.org/sharp 158ms (from cache)
npm timing stage:loadCurrentTree Completed in 2204ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 26ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1364ms
npm http fetch GET 304 https://registry.npmjs.org/semver 85ms (from cache)
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 2027ms
npm timing stage:loadIdealTree Completed in 4114ms
npm timing stage:generateActionsToTake Completed in 173ms
npm verb correctMkdir /home/--redacted--/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /home/--redacted--/.npm/_locks/staging-8093a87111e9e37b.lock for /home/--redacted--/node_modules/.staging
npm timing action:extract Completed in 184ms
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm verb unbuild rmStuff undefined 'from' '/home/--redacted--/node_modules'
npm info lifecycle undefined~postuninstall: undefined
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm verb unbuild rmStuff undefined 'from' '/home/--redacted--/node_modules'
npm info lifecycle undefined~postuninstall: undefined
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm verb unbuild rmStuff undefined 'from' '/home/--redacted--/node_modules'
npm info lifecycle undefined~postuninstall: undefined
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm verb unbuild rmStuff undefined 'from' '/home/--redacted--/node_modules'
npm info lifecycle undefined~postuninstall: undefined
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm verb unbuild rmStuff undefined 'from' '/home/--redacted--/node_modules'
npm info lifecycle undefined~postuninstall: undefined
npm timing action:unbuild Completed in 4ms
npm timing action:remove Completed in 18ms
npm timing action:finalize Completed in 64ms
npm timing action:refresh-package-json Completed in 91ms
npm info lifecycle [email protected]~preinstall: [email protected]
npm info lifecycle [email protected]~preinstall: [email protected]
npm timing action:preinstall Completed in 1ms
npm info linkStuff [email protected]
npm verb linkBins [ { semver: 'bin/semver.js' },
npm verb linkBins '/home/--redacted--/node_modules/sharp/node_modules/.bin',
npm verb linkBins false ]
npm info linkStuff [email protected]
npm timing action:build Completed in 8ms
npm info lifecycle [email protected]~install: [email protected]
npm info lifecycle [email protected]~install: [email protected]

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

info sharp Using cached /home/--redacted--/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz
prebuild-install info begin Prebuild-install version 5.3.3
prebuild-install info looking for cached prebuild @ /home/--redacted--/.npm/_prebuilds/f90d6d-sharp-v0.23.4-node-v57-linux-x64.tar.gz
prebuild-install info found cached prebuild
prebuild-install info unpacking @ /home/--redacted--/.npm/_prebuilds/f90d6d-sharp-v0.23.4-node-v57-linux-x64.tar.gz
prebuild-install info unpack resolved to /home/--redacted--/node_modules/sharp/build/Release/sharp.node
prebuild-install info unpack required /home/--redacted--/node_modules/sharp/build/Release/sharp.node successfully
prebuild-install info install Successfully installed prebuilt binary!
npm verb lifecycle [email protected]~install: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~install: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/--redacted--/node_modules/sharp/node_modules/.bin:/home/--redacted--/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
npm verb lifecycle [email protected]~install: CWD: /home/--redacted--/node_modules/sharp
npm timing audit submit Completed in 625ms
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 623ms
npm timing audit body Completed in 1ms
npm timing action:install Completed in 1901ms
npm info lifecycle [email protected]~postinstall: [email protected]
npm info lifecycle [email protected]~postinstall: [email protected]
npm timing action:postinstall Completed in 2ms
npm verb unlock done using /home/--redacted--/.npm/_locks/staging-8093a87111e9e37b.lock for /home/--redacted--/node_modules/.staging
npm timing stage:executeActions Completed in 2329ms
npm timing stage:rollbackFailedOptional Completed in 73ms
npm timing stage:runTopLevelLifecycles Completed in 9624ms
npm verb saving [ { name: 'sharp', spec: '^0.23.4', save: 'dependencies' } ]
npm verb shrinkwrap skipping write for package.json because there were no changes.
npm info lifecycle undefined~preshrinkwrap: undefined
npm info lifecycle undefined~shrinkwrap: undefined
npm verb shrinkwrap skipping write for package-lock.json because there were no changes.
npm info lifecycle undefined~postshrinkwrap: undefined
npm WARN [email protected] requires a peer of 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 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS: darwin
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: any
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS: linux
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS: darwin
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: any
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS: linux
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64

  • [email protected]
    added 2 packages from 60 contributors, removed 5 packages and audited 22923 packages in 10.821s

35 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

npm verb exit [ 0, true ]
npm timing npm Completed in 11970ms
npm info ok

What is the output of running npx envinfo --binaries --languages --system --utilities?
System:
OS: Linux 4.15 Ubuntu 18.04.3 LTS (Bionic Beaver)
CPU: (16) x64 AMD Ryzen 7 1700 Eight-Core Processor
Memory: 6.81 GB / 15.66 GB
Container: Yes
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 8.10.0 - /usr/bin/node
npm: 6.13.6 - /usr/local/bin/npm
Utilities:
Make: 4.1 - /usr/bin/make
GCC: 7.4.0 - /usr/bin/gcc
Git: 2.17.1 - /usr/bin/git

This is the error I receive when trying to build my Gatsby site:

Something went wrong installing the "sharp" module

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

Remove the "node_modules/sharp" directory, run "npm install" and look for errors
Consult the installation documentation at https://sharp.pixelplumbing.com/en/stable/install/
Search for this error at https://github.com/lovell/sharp/issues

installation

Most helpful comment

SImilar issue, not sure same problem, though: in my case the issue was that ignore-scripts set to true in .npmrc prevented build.

npm config set ignore-scripts false
rm -rf node_modules
npm install

solved for me

All 6 comments

This log suggests prebuilt binaries were successfully found and installed, including node_modules/sharp/build/Release/sharp.node.

prebuild-install info unpack resolved to /home/--redacted--/node_modules/sharp/build/Release/sharp.node
prebuild-install info unpack required /home/--redacted--/node_modules/sharp/build/Release/sharp.node successfully

The Cannot find module '../build/Release/sharp.node' error suggests the same file is no longer present. Is there any other build step that's not shown here that could be failing or removing the file?

I am also experiencing a similar issue.

ERROR
Something went wrong installing the "sharp" module
Cannot find module '../build/Release/sharp.node'

â ‹ load plugins

SImilar issue, not sure same problem, though: in my case the issue was that ignore-scripts set to true in .npmrc prevented build.

npm config set ignore-scripts false
rm -rf node_modules
npm install

solved for me

@peterayeniofficial Please open a new installation issue and answer all of the questions if you still require help.

I had the same issue, but was able to resolve it by using Node 12.x instead. Looks like my CI was running Node 10.x.

@lovell so the sharp.node file wasn't present. I ended up reinstalling everything again, utilizing the --unsafe-perm flag. And it ended up working. Thanks for your help. I'll close this, as you've instructed everyone to open their own issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vermin1337 picture vermin1337  Â·  3Comments

henbenla picture henbenla  Â·  3Comments

jaekunchoi picture jaekunchoi  Â·  3Comments

OleVik picture OleVik  Â·  3Comments

tomercagan picture tomercagan  Â·  3Comments