Node-canvas error || libuuid.so.1: cannot open shared object file: No such file or directory

I want to use the Netlify Functions to create dynamic images with node-canvas. The function can be accessed with a rewrite/redirect I implemented which would make the URL look like this: “https://plotzes-test.netlify.app/img/stats/USERNAME.png”.

If I use netlify dev from the Netlify CLI on my local machine and I go to “http://localhost:8888/img/stats/plotzes.png” for example then it fully works and I’ll get an image like this:

Example image generated with node-canvas

If I upload my site directory to Netlify then it will build perfectly fine, but when I try to run the function I get this error:

Error

{"errorType":"Error","errorMessage":"libuuid.so.1: cannot open shared object file: No such file or directory","trace":["Error: libuuid.so.1: cannot open shared object file: No such file or directory"," at Object.Module._extensions..node (internal/modules/cjs/loader.js:1065:18)"," at Module.load (internal/modules/cjs/loader.js:879:32)"," at Function.Module._load (internal/modules/cjs/loader.js:724:14)"," at Module.require (internal/modules/cjs/loader.js:903:19)"," at require (internal/modules/cjs/helpers.js:74:18)"," at Object.<anonymous> (/var/task/src/node_modules/canvas/lib/bindings.js:3:18)"," at Module._compile (internal/modules/cjs/loader.js:1015:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)"," at Module.load (internal/modules/cjs/loader.js:879:32)"," at Function.Module._load (internal/modules/cjs/loader.js:724:14)"]}

I’ve used Google a lot and apparently libuuid isn’t installed on the AWS Lambda server or something like that, I’m not sure. I’ve come across a lot of issues with this that have been resolved by using a Lambda Layer someone made but you can’t install that with Netlify.

How did I build?
When I upload my site directory to Github I’m not uploading the node_modules directory and thus also not the compiled binaries addons. So while Netlify is building it’s installing the node packages themselves because if it were to use the packages I build on my local machine then I would get an “Invalid ELF header” error.
I also tried to use some build commands that might be able to install the libuuid library for me but none of them worked (yum, apt-get, su, pacman, dnf). I also tried to install the node packages with Docker Desktop but that was totally new to me and I couldn’t get it to work. I know nothing about Linux and its commands.

Here is a build log of a successful build (so without any unknown build commands). I’ve got two functions and this is about the image.js function. I started this build without cache. I’m not sure if this is useful for anyone but just to be sure I’m giving it to you guys! :smiley:

Successfullo no cache build log

12:25:56 PM: Build ready to start 12:25:58 PM: build-image version: 53b83b6bede2920f236b25b6f5a95334320dc849 12:25:58 PM: build-image tag: v3.6.0 12:25:58 PM: buildbot version: a706ec7a557bcc28584843816a376a10c08955ca 12:25:58 PM: Building without cache 12:25:58 PM: Starting to prepare the repo for build 12:25:58 PM: No cached dependencies found. Cloning fresh repo 12:25:58 PM: git clone https://github.com/ImPlotzes/Website-test 12:26:01 PM: Preparing Git Reference refs/heads/main 12:26:03 PM: Starting build script 12:26:03 PM: Installing dependencies 12:26:03 PM: Python version set to 2.7 12:26:05 PM: v12.18.0 is already installed. 12:26:05 PM: Now using node v12.18.0 (npm v6.14.4) 12:26:05 PM: Started restoring cached build plugins 12:26:05 PM: Finished restoring cached build plugins 12:26:05 PM: Attempting ruby version 2.7.1, read from environment 12:26:07 PM: Using ruby version 2.7.1 12:26:07 PM: Using PHP version 5.6 12:26:07 PM: Started restoring cached node modules 12:26:07 PM: Finished restoring cached node modules 12:26:07 PM: Installing NPM modules using NPM version 6.14.4 12:26:14 PM: > canvas@2.6.1 install /opt/build/repo/node_modules/canvas 12:26:14 PM: > node-pre-gyp install --fallback-to-build 12:26:15 PM: node-pre-gyp WARN Using needle for node-pre-gyp https download 12:26:16 PM: [canvas] Success: "/opt/build/repo/node_modules/canvas/build/Release/canvas.node" is installed via remote 12:26:16 PM: npm WARN apiv1@1.0.0 No repository field. 12:26:16 PM: added 80 packages from 37 contributors and audited 80 packages in 8.449s 12:26:17 PM: 4 packages are looking for funding 12:26:17 PM: run npm fund for details 12:26:17 PM: found 0 vulnerabilities 12:26:17 PM: NPM modules installed 12:26:17 PM: Started restoring cached go cache 12:26:17 PM: Finished restoring cached go cache 12:26:17 PM: go version go1.14.4 linux/amd64 12:26:17 PM: go version go1.14.4 linux/amd64 12:26:17 PM: Installing missing commands 12:26:17 PM: Verify run directory 12:26:18 PM: ​ 12:26:18 PM: ──────────────────────────────────────────────────────────────── 12:26:18 PM: Netlify Build 12:26:18 PM: ──────────────────────────────────────────────────────────────── 12:26:18 PM: ​ 12:26:18 PM: ❯ Version 12:26:18 PM: @netlify/build 8.0.3 12:26:18 PM: ​ 12:26:18 PM: ❯ Flags 12:26:18 PM: deployId: 60002a44cd98a4ada2a32149 12:26:18 PM: mode: buildbot 12:26:18 PM: ​ 12:26:18 PM: ❯ Current directory 12:26:18 PM: /opt/build/repo 12:26:18 PM: ​ 12:26:18 PM: ❯ Config file 12:26:18 PM: /opt/build/repo/netlify.toml 12:26:18 PM: ​ 12:26:18 PM: ❯ Context 12:26:18 PM: production 12:26:18 PM: ​ 12:26:18 PM: ──────────────────────────────────────────────────────────────── 12:26:18 PM: 1. Functions bundling 12:26:18 PM: ──────────────────────────────────────────────────────────────── 12:26:18 PM: ​ 12:26:18 PM: Packaging Functions from apiv1 directory: 12:26:18 PM: - image/image.js 12:26:18 PM: - wizcount/wizcount.js 12:26:48 PM: ​ 12:26:48 PM: (Functions bundling completed in 29.6s) 12:26:48 PM: ​ 12:26:48 PM: ──────────────────────────────────────────────────────────────── 12:26:48 PM: Netlify Build Complete 12:26:48 PM: ──────────────────────────────────────────────────────────────── 12:26:48 PM: ​ 12:26:48 PM: (Netlify Build completed in 29.7s) 12:26:48 PM: Caching artifacts 12:26:48 PM: Started saving node modules 12:26:48 PM: Finished saving node modules 12:26:48 PM: Started saving build plugins 12:26:48 PM: Finished saving build plugins 12:26:48 PM: Started saving pip cache 12:26:48 PM: Finished saving pip cache 12:26:48 PM: Started saving emacs cask dependencies 12:26:48 PM: Finished saving emacs cask dependencies 12:26:48 PM: Started saving maven dependencies 12:26:48 PM: Finished saving maven dependencies 12:26:48 PM: Started saving boot dependencies 12:26:48 PM: Finished saving boot dependencies 12:26:48 PM: Started saving rust rustup cache 12:26:49 PM: Finished saving rust rustup cache 12:26:49 PM: Started saving rust cargo bin cache 12:26:49 PM: Finished saving rust cargo bin cache 12:26:49 PM: Started saving go dependencies 12:26:49 PM: Finished saving go dependencies 12:26:51 PM: Build script success 12:26:51 PM: Starting to deploy site from '' 12:26:51 PM: Creating deploy tree 12:26:51 PM: Creating deploy upload records 12:26:52 PM: 0 new files to upload 12:26:52 PM: 2 new functions to upload 12:26:56 PM: Starting post processing 12:26:56 PM: Post processing - HTML 12:26:56 PM: Post processing - header rules 12:26:56 PM: Post processing - redirect rules 12:26:56 PM: Post processing done 12:26:56 PM: Site is live ✨ 12:27:15 PM: Finished processing build request in 1m16.909596769s

Pastebin
Netlify build log - Pastebin.com

How do I fix this error?

1 Like

hi there, sorry to be slow to get back to you. we were a little stumped ourselves! any progress at all on this? :thinking:

Sadly no, but I haven’t really done tried anything new. Just trying the stuff I already tried with the hopes of getting a different result. I don’t really know what new things I can try :thinking:

Hi @Plotzes, I think that the issue is Node-canvas has a binary component that maybe need to be rebuilt. Can you prepend npm rebuild && to your build command and see if that helps?

Hi @Dennis,

I have a similar error with the same node-canvas library which I’m using to render an example png here https://relate-gram.netlify.app/gram/smiley.png.

Your root-cause diagnosis seems right. I’ve tried prepending npm rebuild && to my netlify build command, but that hasn’t helped.

I’ll try other approaches then report back here with any positive results.

Best,
ABK

ps. For reference, the project I’m working on is here GitHub - gram-data/relate-gram: Integration with Relate framework.

Well, after tumbling down a few rabbit holes, I was inspired to try installing the missing libraries using yum or apt.

That is an option on netlify, but suggested a hacky solution: manually including the libraries that would’ve been installed by copying them in place. So that’s what I’ve done.

This image is rendered from an SVG of my netlify function…

What did I do?

  1. spun up an Ubuntu Xenial 16.02 using multipass
    brew install multipass on MacOS
    multipass launch --name netlify xenial
  2. created a shared mount to move files back to MacOS
    mkdir libx86
    multipass mount shared netlify: libx86
  3. started a bash session on the vm
    multipass exec netlify bash to start a session on the vm
  4. installed the libraries required by node-canvas
    sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
  5. copied the missing libraries into the shared mount
    cp /lib/x86_64-linux-gnu/{libblkid,libmount,libuuid}.so.1 libx86
  6. last step, modified the netlify.toml build command to copy those libs into the canvas node_module
    cp ./libx86/* node_modules/canvas/build/Release/

Commit the result, push to github, then smile!

Good enough for now. Hope this helps someone.

Cheers,
ABK

3 Likes

awesome, thanks for sharing!! its complicated solutions that these we rarely get to dig in to!

Oh wow! I don’t have time currently to try this but I definitely will! I’ll update everyone if I can get it to work.

YESSS!!!
It works! Thank you so so so much! :heart:

I almost forgot about this so that’s why my last reply was 5 days ago but I’ve tried it and it works. I had a little bit of trouble with creating the multipass shared mount because I’m not familiar with any kind of Linux stuff, but I got it to work! Honestly thank you!

1 Like

This solution looks to be exactly what I need- having the same problem.

Think you could elaborate on the last step? I think I have the other steps working, but maybe I’m missing how to modify the netlify.toml to get it to work.

To clarify- what does your Toml file look like for this command?

For the “commit result”, I would understand what is happening here to be that we are copying the files into the node modules, but those are currently not in my repo (in my gitignore). Perhaps I’m not understanding perfectly how the deploy process works, but how do these libraries end up in our netlify if we are working on this locally?

Thanks!

Quick update: I did manage to get through the steps in the solution, thank you.

I used this in my toml:
[build] command = "cp ./libx86/* node_modules/canvas/build/Release/"

However I’m still hitting an error, in my deploy if this makes any sense. I’ve tried to manually add the libz.so.1, but so far no luck. @Plotzes what did you do to make it work?
Is this perhaps Node version specific?

Error below, thanks!

7:59:28 PM: 2021-03-07T00:59:28.087Z undefined ERROR Uncaught Exception {"errorType":"Error","errorMessage":"/lib64/libz.so.1: version ZLIB_1.2.9’ not found (required by /var/task/src/node_modules/canvas/build/Release/libpng16.so.16)",“stack”:["Error: /lib64/libz.so.1: version ZLIB_1.2.9' not found (required by /var/task/src/node_modules/canvas/build/Release/libpng16.so.16)"," at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)"," at Module.load (internal/modules/cjs/loader.js:863:32)"," at Function.Module._load (internal/modules/cjs/loader.js:708:14)"," at Module.require (internal/modules/cjs/loader.js:887:19)"," at require (internal/modules/cjs/helpers.js:74:18)"," at Object.<anonymous> (/var/task/src/node_modules/canvas/lib/bindings.js:3:18)"," at Module._compile (internal/modules/cjs/loader.js:999:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)"," at Module.load (internal/modules/cjs/loader.js:863:32)"," at Function.Module._load (internal/modules/cjs/loader.js:708:14)"]}

I am not sure that the node version specific thing. I’ve tried on Node 12 and 14 and neither seem to work. Not sure what I am doing wrong as I copied the code inside the relate-gram repo (GitHub - gram-data/relate-gram: Integration with Relate framework.) very closely.

The error I get now is:


{
  "errorType": "Error",
  "errorMessage": "/lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by /var/task/node_modules/canvas/build/Release/libpng16.so.16)",
  "trace": [
    "Error: /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by /var/task/node_modules/canvas/build/Release/libpng16.so.16)",
    "    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)",
    "    at Module.load (internal/modules/cjs/loader.js:863:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
    "    at Module.require (internal/modules/cjs/loader.js:887:19)",
    "    at require (internal/modules/cjs/helpers.js:74:18)",
    "    at Object.<anonymous> (/var/task/node_modules/canvas/lib/bindings.js:3:18)",
    "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
    "    at Module.load (internal/modules/cjs/loader.js:863:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)"
  ]
}

Looks like Netlify is now using focal for it’s build image, at least for new sites which mine probably falls under. So I thought I’d follow the exact steps, but use focal instead of xenial. I also included libz.so.1 and libpng16.so in my libx86 folder, not sure how important that is. Still no luck yet :sweat_smile:

Is it related to /lib64/libz.so not being inside node_modules/canvas?

hi there @bitttttten - just wanted to let you know we haven’t forgotten about you, and hope to have more info on this soon.

Can you try npm rebuild && [your build command] please?

Rather than copy paste, I’ll share this with you so you can understand what this will do (TL:DR; changing binary versions will likely benefit from an npm rebuild :slight_smile:

I’ve tried all the steps published above, and am still stuck at the “version `ZLIB_1.2.9’ not found” error that everyone else is running into. Do we think there will be a supported path soon to resolve this?

Some further advice in this issue (and this comment was written by one of our own here at Netlify!)

1 Like

Scott, can you provide any more information about customizing that LD_LIBRARY_PATH like Marcus mentions to get Canvas to work? I stumbled across that same comment last night and haven’t been able to get this to work :frowning:

Hi @heyjoshpierce,

You need to set that an an environment variable in Netlify UI as mentioned here:

Edit:
Method 2 below does work to solve the ZLIB_1.2.9 error. Make sure you have properly followed the steps detailed by @devrel-team to solve the libuuid.so.1 error first.

Instead of multipass, on Windows you can also use WSL2 and the Ubuntu 20.04 LTS terminal in the Microsoft Store.


Despite following the advice shared in the linked GitHub issue I wasn’t able to resolve the issue.

I have tried:

  1. setting LD_PRELOAD to /var/task/node_modules/canvas/build/Release/libz.so.1
    It produced a build log full of these errors:
6:17:24 PM: ERROR: ld.so: object '****' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

6:17:24 PM: ERROR: ld.so: object '****' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

6:17:24 PM: ERROR: ld.so: object '****' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
  1. setting LD_LIBRARY_PATH to /var/task/node_modules/canvas/build/Release
    No build errors but the error persists.