-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
"Segmentation fault" on Vercel when used inside Next.js getStaticProps (via Plaiceholder) #2655
Comments
Update: the Vercel team took a look at this and seem to believe it's something on the |
My best guess would be that this relates to the recent introduction of worker threads to Next.js. The backtrace with https://sharp.pixelplumbing.com/install#worker-threads
There's some background to this at #2263. |
Thanks for the details! I'm quite new to the concept of Node.js worker threads, so apologies if I'm missing something obvious here... Would "calling before worker threads" be either:
|
I think this logic is already running inside a worker thread by the time When Next.js removed sharp, they also removed the use of I've been able to reproduce locally, and it looks like simply creating the following, basic require('sharp');
module.exports = {}; If Next.js provides a build-time |
Wow you're absolutely right, that worked perfectly. I'll pass on this message to the Next.js team and see what they'd recommend (config vs. the proposed hook). Thanks so much for your help on this @lovell |
I've found the root of the problem: lovell/sharp#2655 So I added import('sharp') to the main module, now it works. Also added await worker.terminate() instead of worker.unref() for more reliable debugging. Plus, test.sh now uses pnpm run because segmentation faults were occuring more reliably there, which is again - good for debugging. Changed Configuration - now one has to use the provided interface, not the provided class, because the latter didn't work due to circular dependencies. Also updated documentation according to this change.
@lovell is there a way to fix this so requiring sharp from the main thread isn't required? We're having this issue in Vercel with Parcel as well. All Parcel plugins run inside worker threads, and we don't really have a clean way to also require sharp from the main thread before our workers start within our plugin system. |
@devongovett Node.js uses reference counting internally when it calls The logic in https://github.com/sindresorhus/import-fresh might help here, e.g. (untested): require('sharp');
const sharp = require('import-fresh')('sharp'); |
First of all, thank you! Sharp was the fundamental step in the creation of plaiceholder, and I'm extremely grateful for the work you put into maintaining this library.
I recently stumbled across an issue using
sharp
on Vercel after Next.js implemented their WASM-based approach - I was no longer able to usesharp
insidegetStaticProps
in Vercel's environment. I can build the project perfectly locally, but when deployed to Vercel, the following issue occurs.In the example provided,
sharp
is used inside my library plaiceholder.I appreciate this is both a question/issue that might be a bit out of your remit, but I would be really grateful any guidance you could offer here, as infra/deployments are a bit out of my area of expertise. Is there something I can add to
sharp
in plaiceholder to make it more portable? or is this something that could be resolved on thesharp
side?Related Issues
Are you using the latest version? Is the version currently in use as reported by
npm ls sharp
the same as the latest version as reported bynpm view sharp dist-tags.latest
?Uses
[email protected]
(a peerDependency of plaiceholder)What are the steps to reproduce?
Clone the minimal reproduction, and deploy to Vercel.
Alternatively, view the logs of the latest deployment.
What is the expected behaviour?
Given that
sharp
runs successfully as a custom pre-build step on Vercel, I would expectsharp
to run successfully ingetStaticProps
Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?
sharp
usage can be found in plaiceholder'spackages
directoryAre you able to provide a sample image that helps explain the problem?
N/A
What is the output of running
npx envinfo --binaries --system
?Running inside Vercel, I get the following:
The text was updated successfully, but these errors were encountered: