Skip to content

Debian Wheezy: sharp breaks if the canvas module is loaded first #371

Closed

Description

@papandreou

I ran into this very puzzling issue on Debian Wheezy, which I haven't been able to repro on my workstation, which runs a much newer Ubuntu.

It goes something like this:

$ nvm use 4
Now using node v4.3.1 (npm v2.14.12)
$ npm install [email protected] [email protected]
[...]
$ node -e "require('canvas');require('sharp');"

module.js:356
  Module._extensions[extension](this, filename);
                               ^
Error: /path/to/node_modules/sharp/build/Release/../../lib/libgio-2.0.so.0: undefined symbol: g_option_group_unref
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/path/to/node_modules/sharp/index.js:12:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at [eval]:1:19
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:565:25)
    at startup (node.js:80:7)

Interestingly it does not blow up if the two requires are reversed!

It's reproducible with both node.js 0.10.38 and 4.3.1. Haven't tried any others.

Any ideas?

Activity

  1. lovell commented on Mar 2, 2016

    @lovell
    Owner

    I suspect canvas uses a system-wide install of libcairo2-dev, which depends on glib v2.32.4. By introducing this shared library dependency at run-time first, you supersede sharp's pre-packaged glib v2.47.5.

    In this case, it's probably best to follow suit and use a system-wide install of libvips.

  2. nsmag commented on Mar 3, 2016

    @nsmag

    I got this issue too on Ubuntu 14.04.

    Error: /.../node_modules/sharp/build/Release/../../lib/libgio-2.0.so.0: undefined symbol: g_option_group_unref
    

    Sharp ran fine before I installed the canvas.

  3. lovell commented on Mar 3, 2016

    @lovell
    Owner

    Quick thought: are either of you able to try using the fully-versioned path to the shared library (rather than the partial-versioned symlink) in the libraries section of binding.gyp, something like:

    - '<(module_root_dir)/lib/libglib-2.0.so',
    + '<(module_root_dir)/lib/libglib-2.0.so.0.4705.0',
    - '<(module_root_dir)/lib/libgio-2.0.so',
    + '<(module_root_dir)/lib/libgio-2.0.so.0.4705.0',

    Failing this, the only option I can think of is to experiment with the --default-symver linker flag when building the pre-compiled shared libraries to insert the version number into the symbol table.

  4. lovell commented on Mar 3, 2016

    @lovell
    Owner

    Another even quicker thought:

    LD_PRELOAD=/path/to/node_modules/sharp/lib/libglib-2.0.so node script.js

    ...should make sharp's bundled glib take precedence regardless of module import order.

  5. papandreou commented on Mar 22, 2016

    @papandreou
    ContributorAuthor

    Sorry for not reporting back earlier. I just switched around the requires, then moved on :)

    $ LD_PRELOAD=node_modules/sharp/lib/libglib-2.0.so node -e "require('canvas');require('sharp')"
    
    (sharp:61468): GLib-GObject-CRITICAL **: /tmp/buildd/glib2.0-2.33.12+really2.32.4/./gobject/gtype.c:2722: You forgot to call g_type_init()
    
    (sharp:61468): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed
    
    (sharp:61468): GLib-GObject-CRITICAL **: /tmp/buildd/glib2.0-2.33.12+really2.32.4/./gobject/gtype.c:2722: You forgot to call g_type_init()
    
    (sharp:61468): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed
    

    ... and then it hangs.

    If I make the suggested patch to binding.gyp inside node_modules/sharp, then run npm install inside node_modules/sharp, I get the original error:

    $ node -e "require('canvas');require('sharp')"
    
    module.js:356
      Module._extensions[extension](this, filename);
                                   ^
    Error: /home/andreas/playground/node_modules/sharp/build/Release/../../lib/libgio-2.0.so.0: undefined symbol: g_option_group_unref
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:312:12)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.<anonymous> (/home/andreas/playground/node_modules/sharp/index.js:12:13)
        at Module._compile (module.js:456:26)
        at Object.Module._extensions..js (module.js:474:10)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:312:12)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at [eval]:1:19
        at Object.<anonymous> ([eval]-wrapper:6:22)
        at Module._compile (module.js:456:26)
        at evalScript (node.js:565:25)
        at startup (node.js:80:7)
    
  6. lovell commented on Mar 22, 2016

    @lovell
    Owner

    @papandreou Thanks for checking. I guess the dependencies of glib would also need to be included in the LD_PRELOAD variable, a lot of faff compared with moving a couple of require statements :)

    @nsmag Were you also able to "fix" this by altering the require order?

  7. nsmag commented on Mar 22, 2016

    @nsmag

    @lovell Sorry for not reporting back.
    I decided to do some image processing with raw image data from sharp().raw().
    So no need for canvas and I don't want to encounter unexpected surprises in production.

    I'll experiment with canvas + sharp again later.

    Sharp is lightning fast!
    Thanks.

  8. lovell commented on Mar 30, 2016

    @lovell
    Owner

    Glad you both found workarounds. I'll close this for now but please feel free to comment and/or re-open with any more quick fix solutions :)

  9. automata commented on Apr 25, 2016

    @automata

    I was getting the same libgio-2.0.so.0: undefined symbol: g_option_group_unref error and altering require order (i.e. sharp first, then node-canvas) fixed it.

  10. lovell commented on Apr 25, 2016

    @lovell
    Owner

    I did experiment with the -Wl,--default-symver linker flag to force the explicit use of shared library version numbering but couldn't get libtiff to play nicely (and even if I had there may have been further walls I wasn't able to hit) :(

  11. jingsam commented on Jun 16, 2016

    @jingsam
    Contributor

    Any progress to solve this incompatible problem? I got the same error when I uses both sharp and node-canvas

  12. jingsam commented on Jun 17, 2016

    @jingsam
    Contributor

    When I require sharp before canvas, it seems to solve the problem. However, node-canvas will complain Fontconfig error: Cannot load default config file when drawing text.

  13. lovell commented on Jun 17, 2016

    @lovell
    Owner

    @jingsam If you're relying on a system-wide installation of cairo for node-canvas, then the absolute safest option here is to also rely on a system-wide install of libvips for sharp.

  14. Repository owner locked and limited conversation to collaborators on Jun 17, 2016
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