Repository navigation
Description
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
- Running
npm install sharpcompletes without error. - Running
node -e "require('sharp')"completes without error.
Are you using the latest version of sharp?
- I am using the latest version of
sharpas reported bynpm view sharp dist-tags.latest.
What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?
System:
OS: Linux 6.8 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
CPU: (16) x64 AMD Ryzen 7 5700G with Radeon Graphics
Memory: 21.34 GB / 31.19 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 22.13.1 - ~/.nvm/versions/node/v22.13.1/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.13.1/bin/npm
pnpm: 8.5.1 - /usr/bin/pnpm
npmPackages:
sharp: ^0.34.0-rc.0 => 0.34.0-rc.0What are the steps to reproduce?
**
ERROR:/__w/sharp/sharp/node_modules/@img/sharp-libvips-dev/include/vips/VImage8.h:134:vips::VObject& vips::VObject::operator=(const vips::VObject&): assertion failed: (!a.vobject || VIPS_IS_OBJECT(a.vobject))
**
ERROR:/__w/sharp/sharp/node_modules/@img/sharp-libvips-dev/include/vips/VImage8.h:134:vips::VObject& vips::VObject::operator=(const vips::VObject&): assertion failed: (!a.vobject || VIPS_IS_OBJECT(a.vobject))
Bail out! ERROR:/__w/sharp/sharp/node_modules/@img/sharp-libvips-dev/include/vips/VImage8.h:134:vips::VObject& vips::VObject::operator=(const vips::VObject&): assertion failed: (!a.vobject || VIPS_IS_OBJECT(a.vobject))
Bail out! ERROR:/__w/sharp/sharp/node_modules/@img/sharp-libvips-dev/include/vips/VImage8.h:134:vips::VObject& vips::VObject::operator=(const vips::VObject&): assertion failed: (!a.vobject || VIPS_IS_OBJECT(a.vobject))This happens when loading [email protected] on an electron app on Ubuntu 24.04.2, It seems to work fine on other Linux distributions ollm/OpenComic#351 (comment), probably due to different glib version, with [email protected] works correctly in Ubuntu but not in other Linux distributions.
I know this is an issue with electron and glib, but I would like to know if there is a way to make the latest/nexts versions of sharp (v0.34.0-rc.0) work on "old" linux distributions.
Possible temporary/final solution
I'm trying to have 2 versions of sharp installed, the new (v0.34.0-rc.0) and the current (v0.33.5), and use one or the other depending on the glib version detected.
I have tested it on Ubuntu 24.04.2 (Where only v0.33.5 works) and Arch Linux (Where only v0.34.0-rc.0 works), in both it seems to work correctly on an electron app.
The only problem I've noticed is that on build, electron-builder merges the @img folders of both and only keeps the files from one (The installed using an alias), but it seems to work correctly anyway.
Install:
npm install detect-libc
npm install [email protected]
npm install sharp-34@npm:[email protected]Asar unpack:
"asarUnpack": [
"node_modules/sharp",
"node_modules/@img",
"node_modules/sharp-34",
],Load sharp as follows or in a similar way, i'm not sure if the glib version to check should be higher or not, but in Ubuntu it shows version 2.39 and in Arch Linux 2.41:
var sharp = false;
async function loadSharp()
{
if(sharp !== false) return;
if(process.platform === 'linux')
{
const {version} = require('detect-libc');
const number = await version();
if(number)
{
const [major, minor, patch] = number.split('.');
if(major <= 2 && minor <= 39) // Glib 2.39 or less
{
sharp = require('sharp');
return;
}
}
}
sharp = require('sharp-34');
}
Activity
lovell commentedon Mar 25, 2025
Hola Oleguer! As you suggest, this is an ongoing issue relating to glib versioning.
sharp provides libvips as binary statically linked to glib, which attempts to "hide" any glib symbols to avoid exactly the conflict you're seeing - lovell/sharp-libvips#60 has details.
Electron currently dynamically links to the system glib on Linux, although there have been previous recommendations for it to statically link e.g. electron/electron#25495
I'm not entirely sure what else sharp can do here.
ollm commentedon Mar 27, 2025
Hi Lovell, thanks for your response!
For now, I'm using the solution I mentioned earlier, but I have opened a new issue in Electron requesting that electron/electron#25495 it be reopened: electron/electron#46323
If there's anything needs to be changed on the issue, please let me know.
kleisauke commentedon Apr 4, 2025
I wonder if sharp should also built with these defines:
https://github.com/libvips/libvips/blob/v8.16.1/meson.build#L39-L41
That would at least disable those assertions, but perhaps that would cause issues further on.
lovell commentedon Apr 4, 2025
Yes, I agree, we should add those. I also added 6dfb60c earlier today as I realised we were potentially exporting symbols from the prebuilt sharp binaries (we already limit this for the libvips binaries).
Prevent glib assertions and checks #4351
kleisauke commentedon Apr 4, 2025
Great! I think that would work.
For performance reasons, commit a00ee26 could potentially also be done on the Windows-specific
libvips-cpp-<(vips_version)target (i.e. alongside the_VIPS_PUBLICdefine). Alternatively, we could consider removing theseg_assert()'s entirely fromVImage8.h.Prevent glib assertions and checks #4351
lovell commentedon Apr 4, 2025
Commit a9e1913 adds this for the Windows binaries too (missed the v0.34.0 release, but of lower importance as it's only Linux where this problem occurs).
fix: Pin release workflow to ubuntu-22.04 for sharp compatibility #812
Prevent glib assertions and checks lovell#4351
Prevent glib assertions and checks lovell#4351