Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find module './build/Release/sharp'

I'm trying to run some NodeJS code using Sharp and i'm getting the following error:

    [root@localhost myapp-backend]# node server.js 

module.js:340
    throw err;
    ^
Error: Cannot find module './build/Release/sharp'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/root/myapp-backend/node_modules/sharp/index.js:11:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/root/myapp-backend/server.js:277:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

Any ideas?

Thank you.

like image 964
Daimen Worrall Avatar asked Nov 06 '15 12:11

Daimen Worrall


2 Answers

Turns out the Debian 8.x distribution I used did not include vips but I did not get an error message. Running

apt-get install libvips

followed by

npm install sharp

resolved the problem and sharp is finally installed and working.

like image 130
Juergen Amft Avatar answered Oct 05 '22 07:10

Juergen Amft


It's probably due to Sharp not getting installed. When I installed it via npm, there were no errors, but when I went into node_modules/sharp, three were no build files.

You can try to build it by doing
node-gyp rebuild

But, before that, make sure you have Vips installed - that's a lib that Sharp uses. On Mac you'd do
brew install homebrew/science/vips --with-webp --with-graphicsmagick

After you build the Sharp library, you should be good to go.

like image 24
JavaScript Warrior Avatar answered Oct 05 '22 06:10

JavaScript Warrior