Git Product home page Git Product logo

Comments (6)

stefcameron avatar stefcameron commented on June 11, 2024 4

I was hitting this on my M2 mac and noticed it was trying to compile the binary for 2 reasons:

  1. I was using Node 21, which was generating an assumed pre-built binary path including ...node-v120... while the latest canvas v2.11.2 release indicates it's the first release using Node v20. There are no binary paths for the release with node-v120 in them.
    • If I use Node v20.11.1, then the generated download path includes node-v115 which is a match.
  2. I was using my M2 mac, resulting in a download path ending in ...arm64.tar.gz (ARM x64) while all paths end in ...x64.tar.gz (Intel x64).

Because the download was failing for both reasons (I presume it would fail on an Intel mac running Node v21 as well because of (1)), npm was now wanting to compile a new binary.

The compilation would then fail because of a missing pixman-1 package. I installed that and then it failed on missing cairo.

Thankfully, I checked out the README and found that there are a bunch of compilation instructions (thank you -- would be great to mention this in the Release docs too, right after the Node version info...) for various platforms suggesting to run this on Mx macs:

$ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

During the install of cairo, I noticed Brew installed [email protected] as a dependency. So once the installation of all packages was finished, I used pyenv to set my active Python version to 3.12.1 and then ran:

$ npm install canvas  # SUCCESS 🎉

Hope this helps...

from node-canvas.

zachrattner avatar zachrattner commented on June 11, 2024 1

@coderfin Thank you! Will check that out

from node-canvas.

mn4367 avatar mn4367 commented on June 11, 2024 1

I can confirm this, using Node 21 seems to be impossible at the moment as @stefcameron mentioned. Following the build instructions from the README I never really had problems building the canvas module on an MacBook Air with M1 for a long time until I switched to Node 21. Falling back to Node 20 the installation works. Maybe it's worth mentioning this also in the README.

from node-canvas.

polnikale avatar polnikale commented on June 11, 2024 1

@coderfin goooosh, thanks a lot of that, man

I've been bumping into different random issues with fonts for 2 days straight, switched to alternative and it JUST WORKS WOW

OMG lifesaver

from node-canvas.

coderfin avatar coderfin commented on June 11, 2024

I'm not associated with this project or https://github.com/Brooooooklyn/canvas but I found that https://www.npmjs.com/package/@napi-rs/canvas is a great replacement for node-canvas. @napi-rs/canvas supports Intel and Arm (M Chip) Macs with no system dependencies. It supports all the same features that I needed. It also supports webp which was a welcome bonus and is MIT license.

Instead of registerFont use GlobalFonts.registerFromPath; createCanvas and loadImage remain the same.

from node-canvas.

k0d3r1s avatar k0d3r1s commented on June 11, 2024

you can build canvas from source, you will need python3/python3-dev packages + install requirements for canvas. if all required things are found, node-gyp should build canvas from source

from node-canvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.