I’m running into problems when trying to set up the canvas library on my Windows machine through npm. Every time I run the installation command, I keep getting an error that says ‘node-waf’ is not recognized as a valid command.
npm install canvas
The error output looks like this:
'node-waf' is not regonized as an internal or external command, operable program or batch file.
I’m wondering if there’s a way to get node-waf working on Windows, or maybe there’s a different approach I should be using to install this module? Any suggestions would be really helpful since I’m stuck on this.
canvas sucks on windows. Install visual studio build tools with chocolatey first: choco install visualstudio2019buildtools. restart your terminal after. that node-waf error doesn’t matter - it’s old. just make sure you’ve got python 3.x installed since canvas needs it to compile.
Hit this same issue six months back - canvas package is a nightmare on Windows. That ‘node-waf’ error means you’re missing C++ build tools for compiling native modules. Skip the headache and use ‘@napi-rs/canvas’ instead. It’s got N-API bindings so you won’t deal with Windows build issues. Just run ‘npm install @napi-rs/canvas’ and you’re good to go. API’s basically identical, so your code won’t need much tweaking. Beats spending hours messing with Visual Studio build tools and Python deps.
The issue with ‘node-waf’ arises from the fact that it is an outdated build tool that newer versions of Node.js do not utilize. I encountered this challenge last year while working on a graphics-related project. A solution that worked for me was to install ‘windows-build-tools’ with admin permissions by running ‘npm install --global windows-build-tools’. This installation takes care of the Visual Studio prerequisites and Python dependencies necessary for compiling the canvas library. After installation, restart your command prompt and attempt to install the canvas library again. If problems persist, consider using ‘node-canvas’ instead, as it tends to perform better on Windows. Ensure that your Node.js version is 14 or above, as older versions may conflict with native modules like canvas.