Skip to content

chore: upgrade sharp to 0.35.2#594

Draft
lovell wants to merge 1 commit into
vercel:mainfrom
lovell:sharp-dual-esm-cjs
Draft

chore: upgrade sharp to 0.35.2#594
lovell wants to merge 1 commit into
vercel:mainfrom
lovell:sharp-dual-esm-cjs

Conversation

@lovell

@lovell lovell commented Jun 12, 2026

Copy link
Copy Markdown

Extends the sharp "special case" with additional ESM/CJS-specific paths added in v0.35.0.

No longer requires the "special case" from 0.35.2 onwards.

The existing path check remains to support older versions and future-proof for when we switch to ESM-only.

@lovell lovell requested review from a team, icyJoseph, ijjk and styfle as code owners June 12, 2026 09:45
@socket-security

socket-security Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​sharp@​0.35.2-rc.29710010095100

View full report

@styfle

styfle commented Jun 12, 2026

Copy link
Copy Markdown
Member

@lovell I wouldn't expect the special case to be required now that sharp fixed the logic to be statically analyzable here:

I think we should figure out the failure mode instead of changing the special case (the special case should just be for old versions of sharp)

@lovell

lovell commented Jun 14, 2026

Copy link
Copy Markdown
Author

The prebuilt sharp packages e.g. @img/sharp-linux-x64 are now correctly discovered, however the prebuilt libvips packages e.g. @img/sharp-libvips-linux-x64 are not.

For a file to be considered necessary, is it enough to reference that file in the exports of a package.json file or does it have to be part of a require or import statement in code?

@styfle

styfle commented Jun 16, 2026

Copy link
Copy Markdown
Member

Typically it needs to be part of a require() or import or readFile() to be statically analyzed and emitted, but there is a bit more nuance.

For example this sharedLibEmit() does some magic that might be relevant here:

export async function sharedLibEmit(p: string, job: Job) {

@styfle

styfle commented Jun 16, 2026

Copy link
Copy Markdown
Member

I had claude try a few different solutions and they were pretty verbose since it tried to parse the .node binary to find the dependencies.

One of the solutions was much more simple seen here:

However, it feels relatively similar to the special case we already have for sharp here (checking package.json for optionalDependencies), so I'm thinking we might as well merge your PR since its less risk.

Comment thread test/integration.test.js Outdated
JSON.stringify({
packageManager: 'pnpm@8.14.3',
dependencies: { sharp: '0.33.2' },
dependencies: { sharp: '0.35.1' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets rever this to the old version so we still have coverage for the old version

@lovell

lovell commented Jun 16, 2026

Copy link
Copy Markdown
Author

How about a possible alternative where the @img/sharp-libvips-* packages (for macOS and Linux) export an empty/stub .node file to make the dependency a bit more concrete?

For example, the logic in @img/sharp-linux-x64 could be modified to include something like:

try { require('@img/sharp-libvips-linux-x64/empty.node') } catch {}

This might be enough for the existing sharedLibEmit logic to then discover the other shared libraries, assuming require errors are ignored.

@styfle

styfle commented Jun 17, 2026

Copy link
Copy Markdown
Member

@lovell Yes that would be great!

The special case is no longer required for sharp >= 0.35.2 as it
can take advantage of the existing sharedLibEmit logic.
@lovell lovell force-pushed the sharp-dual-esm-cjs branch from 1c7aa85 to 6e02aec Compare June 18, 2026 10:56
@lovell lovell marked this pull request as draft June 18, 2026 11:13
@lovell

lovell commented Jun 18, 2026

Copy link
Copy Markdown
Author

I've published a release candidate v0.35.2-rc.2 of sharp with the stub.node approach and it appears to work with the existing sharedLibEmit logic and doesn't require the special case handling.

Marking this PR as draft for now until after v0.35.2 is released and the 2-day new package cool-down has passed.

I note the logic in TurboPack is slightly different from the logic in this package as it only has an ends_with check rather than a more comprehensive regex. I don't think this will work with common filenames like shared.so.1.2.3.

sharedlibGlob = '/**/*.so?(.*)';

https://github.com/vercel/next.js/blob/c5a826f59d9385363774c292d420bdfb54f02ec2/turbopack/crates/turbopack-resolve/src/node_native_binding.rs#L147

@lovell lovell changed the title fix: sharp dual ESM/CJS chore: upgrade sharp to 0.35.2 Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants