Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sharp no longer optional since 10.0.4-canary.7 #20456

Closed
jorrit opened this issue Dec 24, 2020 · 23 comments · Fixed by #22253
Closed

sharp no longer optional since 10.0.4-canary.7 #20456

jorrit opened this issue Dec 24, 2020 · 23 comments · Fixed by #22253
Assignees
Milestone

Comments

@jorrit
Copy link
Contributor

jorrit commented Dec 24, 2020

Bug report

Describe the bug

Next.js has an optional dependency on sharp. This means that it should run without sharp present in node_modules.

PR #20035 broke this by adding require.resolve('sharp') without a try/catch to catch MODULE_NOT_FOUND.

I discovered this because sharp no longer installs with NPM 7 (see #20432).

To Reproduce

npm i [email protected]
rimraf node_modules/sharp
npm run build

Build error occurred
Error: Cannot find module 'sharp'
Require stack:

  • C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\build\index.js
  • C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\cli\next-build.js
  • C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\bin\next
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.resolve (internal/modules/cjs/helpers.js:94:19)
    at build (C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\build\index.js:11:794) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    'C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\build\index.js',
    'C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\cli\next-build.js',
    'C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\bin\next'
    ]
    }

Expected behavior

The site builds OK.

  • OS: Windows or Linux (alpine in docker)
  • Version of Next.js: 10.0.4-canary.7 and up
  • Version of Node.js: 14 (latest)
  • Deployment: fails on build
@jorrit jorrit added the bug Issue was opened via the bug report template. label Dec 24, 2020
@jorrit
Copy link
Contributor Author

jorrit commented Dec 24, 2020

Perhaps a CI test that removes sharp after installing the dependencies would prevent this in the future.

@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers kind: bug and removed bug Issue was opened via the bug report template. labels Jan 3, 2021
@timneutkens timneutkens added this to the 10.x.x milestone Jan 3, 2021
@timneutkens
Copy link
Member

Feel free to send a PR!

@thien-do
Copy link
Contributor

thien-do commented Jan 4, 2021

Tks for the report and PR @jorrit !

npm i [email protected]

I don't really know why but this happens in 10.0.4 (the latest version, not the canary one) too

image

@jorrit
Copy link
Contributor Author

jorrit commented Jan 4, 2021

Canary-7 was the version the bug got introduced in, it is also in the later canary versions and the final version.

@iou90

This comment has been minimized.

@davidgilbertson

This comment has been minimized.

sct added a commit to sct/overseerr that referenced this issue Jan 8, 2021
elliottsj added a commit to elliottsj/nextjs-vercel-pnpm-issue that referenced this issue Jan 10, 2021
@paxelpixel
Copy link

same issue. could not deploy to aws

@paxelpixel
Copy link

is there a temporary fix for this?

@ChristianPraiss
Copy link

ChristianPraiss commented Feb 3, 2021 via email

@paxelpixel
Copy link

thank you much brother! unfortunately, it didn't work. I spent 8 hours trying to make this work on the beanstalk. no luck
went back to vercel and it worked in less than a minute. hopefully, there is official a guide for aws

@firefart
Copy link

firefart commented Feb 8, 2021

Any update on this? This introduces so many new dependencies that previous docker images fail to build because this now requires sharp which reuqires python3 and so on. This currently prevents us from upgrading to the latest next.js version

@vtenfys
Copy link

vtenfys commented Feb 8, 2021

@firefart a PR is open to fix this (#20738) although the Next.js maintainers haven't responded to it yet

@orzklv
Copy link

orzklv commented Feb 8, 2021

For macos users: brew install libvips and voila!
For debian users: apt install libvips approximate answer, I dunno how is it called on debian & arch package managers...

Also, don't forget to upgrade it if it exists already!

@onigoetz
Copy link

onigoetz commented Feb 8, 2021

@genemators If only that was that easy.

What about corporate environments that just can't download things from the internet for builds, only from an npm mirror ?
That's the reason this dependency was made optional in the first place.

@orzklv
Copy link

orzklv commented Feb 8, 2021

@genemators If only that was that easy.

What about corporate environments that just can't download things from the internet for builds, only from an npm mirror ?
That's the reason this dependency was made optional in the first place.

I dunno dude, this is just a temporary solution.

@cseas
Copy link

cseas commented Feb 12, 2021

Having "sharp" as a dependency is a bit of a problem on corporate systems because those terminals usually aren't allowed to fetch anything directly from GitHub which is exactly what the sharp install keeps trying to do.

Related StackOverflow thread:
https://stackoverflow.com/questions/65894000/install-sharp-without-github-fetch-for-nextjs-error-cannot-find-module-sharp

@Timer Timer added point: 5 and removed good first issue Easy to fix issues, good for newcomers labels Feb 17, 2021
@Timer Timer self-assigned this Feb 17, 2021
@kodiakhq kodiakhq bot closed this as completed in #22253 Feb 18, 2021
kodiakhq bot pushed a commit that referenced this issue Feb 18, 2021
This pull request removes the native `sharp` dependency (which doesn't work on some Linux variants, nor **M1 Mac**) and replaces it with a wasm equivalent.

It also reduces Next.js' installed size by 27.3 MB.

The code is adapted from the [Squoosh CLI](https://github.com/GoogleChromeLabs/squoosh).

This PR still supports:

- Rotation normalization
- Resizing
- PNG
- JPEG
- Webp

However, it (temporarily) removes support for:
- Resizing Gifs
- Resizing Tiff

(these formats still get served and rendered correctly by the image component)

---

Fixes #20456
Closes #20738
Closes #21762
@robertveloso
Copy link

Thanks for kodiakhq for the effort to replace sharp, but this was closed and the problem persist in the latest version.

Best regards.

@vtenfys
Copy link

vtenfys commented Feb 20, 2021

@robertveloso A new stable version hasn't yet been released since the fix, but if you install the latest preview version (currently 10.0.8-canary.5) you'll find it fixes the issue :)

@EduardoHidalgo
Copy link

EduardoHidalgo commented Feb 22, 2021

brew install libvips

Thank you @genemators :D now im downloading all the deep web and google server files on my desktop <3

maveonair added a commit to maveonair/harbour that referenced this issue Feb 24, 2021
@orzklv
Copy link

orzklv commented Feb 25, 2021

brew install libvips

Thank you @genemators :D now im downloading all the deep web and google server files on my desktop <3

Bruh, it was just an option ...

@lewyuburi
Copy link

lewyuburi commented Feb 26, 2021

For Arch Linux (or Arch Linux based distro likes Manjaro), try sudo pacman -S libvips

@habib786
Copy link

habib786 commented Jun 8, 2021

Doesn't work in mac.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.