Repository navigation
fix: emit libvips shared library for [email protected] - #595
styfle wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Just a note that this is biting in production, in case it helps with prioritising. We hit it on Next.js 16.2.12 (Turbopack, Vercel, pnpm, linux-x64) upgrading sharp 0.34.5 → 0.35.3 to clear GHSA-f88m-g3jw-g9cj: Every route whose import graph reached sharp returned a 500 at module init. The same failure is being reported in lovell/sharp#4567 and vercel/next.js#96064. Two things that might be worth folding in:
|
|
I think this PR has been superseded by #594. As of sharp v0.35.2+ the special case logic is no longer required, although it is retained for now to continue to support older versions. As an aside, there might still be an ongoing problem with Turbopack if it does not follow |
|
Agreed - closing in favor of #594 |
|
I'll bump the turbopack test here to verify if this is a turbopack issue: vercel/next.js#96386 Update: looks like tests pass 😌 |
Problem
[email protected]reorganized its prebuilt binaries. The platform package (e.g.@img/sharp-darwin-arm64) loads its native.nodeaddon, which in turn dlopens the libvips shared library (libvips-cpp.*.dylib/.so/.dll) from a sibling package,@img/sharp-libvips-<platform>. Because that load happens inside the compiled binary rather than via a JSrequire, static analysis never saw it, so the shared library was missing from the trace and the bundled app failed at runtime withCannot find module/ dlopen errors.The previous
sharpspecial case keyed onsharp/lib/index.js, which[email protected]moved todist/, so it silently stopped firing.Fix
Two complementary mechanisms, covering old and new sharp:
sharedLibEmitalready runs whenever a.nodefile is emitted and globs the binary's own package for shared libraries. It now also reads that package'spackage.jsonand emits the shared libraries from eachoptionalDependenciespackage (resolved relative to thenode_modulesroot, withrealpathso pnpm symlink layouts work). This is version-independent: it follows the declared dependency (@img/sharp-libvips-<platform>) rather than hardcoding paths.require(path)over a list of candidate specifiers), so the existingsharpspecial case inspecial-cases.tsis kept for that case, with a clarifying comment.Validation
node out/cli.js print test/integration/sharp.jsnow lists@img/sharp-libvips-<platform>/lib/libvips-cpp.*.pnpm test test/integration.test.jspasses all 89 tests, including:sharp.js(sharp 0.35.1 → manifest path)sharp-pnpm.js(sharp 0.33.2 → special-case path)🤖 Generated with Claude Code