Skip to content

Sharp v0.34.0-rc.0 crashes in Ubuntu 24.04.2 on an electron app #4351

Closed

Description

@ollm

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes 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 sharp as reported by npm 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.0

What 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.

Related: #4129 and #4348

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

  1. lovell commented on Mar 25, 2025

    @lovell
    Owner

    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.

  2. ollm commented on Mar 27, 2025

    @ollm
    Author

    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.

  3. kleisauke commented on Apr 4, 2025

    @kleisauke
    Contributor

    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.

  4. lovell commented on Apr 4, 2025

    @lovell
    Owner

    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).

  5. kleisauke commented on Apr 4, 2025

    @kleisauke
    Contributor

    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_PUBLIC define). Alternatively, we could consider removing these g_assert()'s entirely from VImage8.h.

  6. lovell commented on Apr 4, 2025

    @lovell
    Owner

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions