Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install sharp without GitHub fetch for Nextjs: Error: Cannot find module 'sharp'

I'm trying to use Next.js on my corporate system, but whenever I run "npm run build", the build fails with the message: Error: Cannot find module 'sharp'

I tried installing sharp but I get this error:

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.5/libvips-8.10.5-win32-x64.tar.br 
ERR! sharp getaddrinfo ENOTFOUND github.com 
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/install for required dependencies

This is probably because github URLs are blocked on my system's terminal due to security reasons. Is there a way to install sharp without fetching from github? I can access GitHub on the browser, so if downloading the file from there and then installing it somehow is possible I can do that.

OS: Windows 10

like image 337
Abhijeet Singh Avatar asked Jan 25 '21 23:01

Abhijeet Singh


2 Answers

UPDATE: NextJS v10.0.8 fixes this issue! If you're running into the above error: upgrade to the 10.0.8 (or beyond).

The required sharp dependency introduced with NextJS 10.0.5 has broken builds that depend on the underlying libvips, which isn't there in various Linux distros. They're working on making the dependency optional. Relevant PR here and here. Related issue here. This may be easier than trying to get libvips installed or compiled on your machine (I simply couldn't get it to work on my Amazon EC2 ARM-based machine). You can downgrade to NextJS 10.0.3 in the meantime. I think they'll fix it soon.

like image 62
Martin Devillers Avatar answered Oct 02 '22 19:10

Martin Devillers


I had the same error. It was happening to me because I have the Apple M1 Mac. I solved the error installing Homebrew, and after that, I had to install 'lipvips' using Brew install vips. Then, inside my project, npm install sharp, and finally, I run npm run build and it worked fine for me. I Hope It works for you!

like image 38
SergioGaitan Avatar answered Oct 02 '22 21:10

SergioGaitan