Automattic/node-canvas

⭐ How to Troubleshoot Installation

zbjornson opened this issue · 15 comments

The majority of issues opened in node-canvas are for installation help. This post is an experiment to see if we can help users help themselves to troubleshoot installations.

Installation fails with a 404 in the log

If you have an ARM CPU, including an Apple M1 or M2

Prebuilds aren't available for ARM. Please see the wiki for guides on building from source. See also node-gfx/node-canvas-prebuilt#69.

If you're on Alpine Linux or another distro using musl-libc

The log may look like

node-pre-gyp WARN Tried to download(404): https://github.com/node-gfx/node-canvas-prebuilt/releases/download/v2.6.0/canvas-v2.6.0-node-v64-linux-musl-x64.tar.gz

Prebuilds are only available for glibc, not musl-libc. See node-gfx/node-canvas-prebuilt#77, which includes information on building from source.

If you're using Electron

The log may look like

node-pre-gyp WARN Tried to download(404): https://github.com/node-gfx/node-canvas-prebuilt/releases/download/v2.6.0/canvas-v2.6.0-electron-v3.0-win32-unknown-x64.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for canvas@2.6.0 and electron@3.0.11 (electron-v3.0 ABI, unknown) (falling back to source compile with node-gyp)

There are no prebuilds available for Electron. Please see the wiki for guides on building from source. See also node-gfx/node-canvas-prebuilt#84 or #1467.

If a new version of Node.js was recently released

The log may look like

node-pre-gyp WARN Tried to download(404): https://github.com/node-gfx/node-canvas-prebuilt/releases/download/v2.6.0/canvas-v2.6.0-node-v79-win32-unknown-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for canvas@2.6.0 and node@13.3.0 (node-v79 ABI, unknown) (falling back to source compile with node-gyp)

We manually publish prebuilt versions of node-canvas, and it can take some time for us to catch up.

You can see the list of available prebuilds here (expand the "Assets" section under the version you're trying to install): https://github.com/node-gfx/node-canvas-prebuilt/releases.

If you're using 32-bit Node.js

The log will include a 404 and ia32. Node-canvas does not readily compile on 32-bit platforms because the necessary dependencies are hard to obtain. Use 64-bit Node.js instead, especially because 32-bit Node.js is only experimentally supported by the Node foundation.

I get a permissions error (EACCES)

Possibly your node_modules or an npm or yarn cache or temp directory is owned by a different user. Review the error log to see what folder you don't have permission to access. See #1429 for an example, or any of these issues.

If you were trying to install with sudo, try without. (See issues.)

I get a NODE_MODULE_VERSION error

The log may look like

...was compiled against a different Node.js version using NODE_MODULE_VERSION 72.
This version of Node.js requires NODE_MODULE_VERSION 64. Please try re-compiling or
re-installing the module

This could mean you upgraded Node.js without re-installing canvas. Try running yarn or npm install again.

This can also happen if you're using Electron. The version of Node wrapped by Electron must match the version of Node that you used to build/install canvas.

Installation fails with lots of compiler errors, including ...was declared deprecated and/or no viable conversion and/or 'Handle' is not a member of 'v8'

You're probably trying to install an old version of node-canvas. Version 2.x is required for Node.js v6.x and later. Version 2.5.x or later is required for Node.js v12.x and later. Check if your package.json or lock file specifies an old version.

I get a the specified procedure could not be found error

If you have Sharp.js also installed, there's an incompatibility between their build of Cairo and our build of Cairo. See #930.

I get the error canvas.node is not a valid Win32 application.

This usually means you have 32-bit Node.js and 64-bit node-canvas, or vice versa. They must be the same (and you should prefer 64-bit over 32-bit). You can check this is the issue using the instructions in #1533 (comment). It can also mean you're trying to use the Linux or Mac build from Windows.

I get a GLIBC version error

If you installed Node.js with snaps

Error: /snap/core/current/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25'
not found (required by /lib/x86_64-linux-gnu/libuuid.so.1)

This can happen if you installed Node.js with snaps instead of apt/dpkg, and if the snap core has an older version of glibc. (Background: #1959.)

If you're on CentOS 7 or EL 7

error: /lib64/libc.so.6: version `GLIBC_2.18` not found (required by 
...(project_dir).../node_modules/_canvas@2.8.0@canvas/build/Release/librsvg-2.so.2)

CentOS 7 and EL 7 use GLIBC 2.17, but v2.8.0+ of node-canvas were prebuilt with v2.24 from Debian Stretch. That is the minimum version of glibc required to use node-canvas 2.8.0+. For now, a workaround is to use node-canvas 2.7.0, or build from source.

Module did not self-register

Node-canvas isn't compatible with worker threads yet, see #1394. Canvas needs to be ported from NAN to N-API (#923).


To keep this issue concise and on-topic, (1) comments asking for help will be deleted, please open a separate issue instead, (2) comments with suggestions for improving the troubleshooting are welcome and will be hidden after incorporating into this top post.

Hey I am getting the NODE_MODULE_VERSION issue but mine says
was compiled against a different Node.js version using NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 80. Please try re-compiling or re-installing

I tried reinstalling but its not helping. I can see that in your example, the later version is lower, which is different in mine. Any clue on how to fix this ?

I tried building from source, I am on ubuntu 16.04 and I used npm install --build-from-source canvas. But this didn't work either

I get the same issue as @vipul-vinsol on node v12.16.3.

Error: The module '/Users/nathan/gitrepos/exif-extractor/node_modules/canvas/build/Release/canvas.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 82. Please try re-compiling or re-installing

I've tried deleting node_modules and npm i again (and again and again). I've tried npm install canvas --build-from-source several times. Nothing works.

tngan commented

@ndtreviv I have encountered the same issue as you mentioned, I am using the latest node version 12.19.1 though. Have you resolved the version conflict issue?

@ndtreviv I have encountered the same issue as you mentioned, I am using the latest node version 12.19.1 though. Have you resolved the version conflict issue?

I did. I was using the module inside an electron app. Electron seems to run with its own version of node. In my case I had to find out what version of node electron was running, and rebuild the module to fit that version.
I did this by using node version manager (nvm) to install the same version of node that electron is bundled with and switched to that version before running the rebuild command.

@vipul-vinsol @ndtreviv please open issues for installation questions. I want to keep this issue clean so it's an easy troubleshooting reference.

@vipul-vinsol Which one is older/newer doesn't matter, it's just the mismatch that matters. There's no release version of Node.js that has NODE_MODULE_VERSION 80; are you using Electron or a custom build?

If you have Sharp.js also installed, there's an incompatibility between their build of Cairo and our build of Cairo. See #930.

And on the sharp documentation:

The prebuilt binaries provided by canvas for Windows depend on the unmaintained GTK 2, last updated in 2011.

These conflict with the modern, up-to-date binaries provided by sharp.

If both modules are used in the same Windows process, the following error will occur:
The specified procedure could not be found.

So.. I'm wondering what the expected way forward is here? I've been using sharp for image processing and Paper.js which uses node-canvas for other vector processing on top of that. I need to use them both- but the discourse between these projects seems to imply this is now some kind of impasse?

I've spent the whole day trying to get my project to run and I'm facing the same error every time, wondering if I need to now make a choice between these dependencies and try and move on.

was compiled against a different Node.js version using
NODE_MODULE_VERSION 93. This version of Node.js requires
NODE_MODULE_VERSION 102. Please try re-compiling or re-installing.
I tried everything and still nothing.

Using canvas 2.8.0 on OSX 10.13.6, node 14.17.6
I had a lot of trouble finding how to use canvas in this configuration.

The typical error was

dyld: lazy symbol binding failed: Symbol not found: ____chkstk_darwin
  Referenced from: /Users/*user*/*project*/node_modules/canvas/build/Release/libpixman-1.0.40.0.dylib (which was built for Mac OS X 10.15)
  Expected in: /usr/lib/libSystem.B.dylib

dyld: Symbol not found: ____chkstk_darwin
  Referenced from: /Users/*user*/*project*/node_modules/canvas/build/Release/libpixman-1.0.40.0.dylib (which was built for Mac OS X 10.15)
  Expected in: /usr/lib/libSystem.B.dylib

and crashing the app.

The solution that worked for me:
npm i canvas as normal
Replacing
.../node_modules/canvas/build/libpixman-1.0.40.0.dylib
with
/usr/local/Cellar/pixman/0.40.0/lib/libpixman-1.0.40.0.dylib

Note:
I use only a small part of the capabilities of canvas in this particular project. As such this solution might not work for your needs.
I expect this to work also for variants of the canvas version and node versions.

I hope this helps at least some of you.

Use case
Migrating Gaia-online from
Hapi.js 18.4.0 / node 12.10.0
to
Hapi.js 20.2.1 / node 14.17.6 (or higher).
Canvas is used for the face recognition login.
The migration work is still ongoing.

@ThunderDoesDev

was compiled against a different Node.js version using NODE_MODULE_VERSION 93. This version of Node.js requires NODE_MODULE_VERSION 102. Please try re-compiling or re-installing. I tried everything and still nothing.

I've the same now, and ite project is build in a docker container, so the npm install was successfully ran.
Have you found a solution ?

image

image

Can #1965 be solved with any of these suggestions?

@mjchang #1965 is covered in this part:

If you have an ARM CPU

Prebuilds aren't available for ARM. Please see the wiki for guides on building from source. See also node-gfx/node-canvas-prebuilt#69.

Hi, any help appreciated to tell me which apk modules I am missing here disney/meteor-base#108 ?

in short I am getting Error: Error loading shared library libcairo.so.2: No such file or directory (needed by /opt/bundle/bundle/programs/server/npm/node_modules/canvas/build/Release/canvas.node) which I tried to load with

RUN apk add --update --no-cache --virtual build-deps \
      python \
      g++ \
      build-base \
      cairo-dev \
      jpeg-dev \
      pango-dev \
      musl-dev \
      giflib-dev \
      pixman-dev \
      pangomm-dev \
      libjpeg-turbo-dev \
      freetype-dev \
    && npm ci \
    && apk del build-deps \
    && apk add --no-cache \
      cairo \
      jpeg \
      pango \
      musl \
      giflib \
      pixman \
      pangomm \
      libjpeg-turbo \
      freetype

    
RUN	npm install canvas@2.9.0

But I must be missing something / wrong name - any help appreciated

Why you just don't provide already compiled code on ARM ?

when canvas-v2.10.0-node-v108-linux-glibc-x64.tar.gz will be published ?
we need use node v18LTS,but canvas can not be installed,build in installing looks not good for me.

For anyones struggling to install node-gyp on M1 Mac machine https://dev.to/steckdev/setting-up-m1m2-mac-for-using-package-node-gyp-1d9e