chartjs-node-canvas install (build) error - node.js

I want to render a chart to use with my discord bot and so far all the tutorials i have seen are using the chartjs-node-canvas module. But it gives errors when installing.
If someone gives me an alternative package to chartjs-node-canvas this is perfectly fine but i would prefer just solving this error and using the existing package.
Since stackoverflow does not allow adding text files (and if i just paste the text it is more than 30000 characters) here is a link to a pastebin with the npm log
pastebin.com/raw/yXrTyq85

I believe the problem lies in the installation of node-canvas which is a dependency for chartjs-node-canvas. After spending a lot of time researching why the library isn't getting installed, I got a lead to the following link: https://github.com/Automattic/node-canvas/wiki#installation-guides
I installed the below-mentioned dependencies on my machine and used a node version of 16.x
This did the work for me.
Here is how I installed the required dependencies:
brew install pkg-config cairo pango libpng jpeg giflib librsvg
After installing these dependencies, you can install the library using npm or yarn.

Related

Cross platform support Sharp Node.JS

I was having trouble using Sharp (npm i sharp) in two different computers, a Mac and a Linux.
I was getting the following error:
Error:
Something went wrong installing the "sharp" module
Cannot find module '../build/Release/sharp-darwin-x64.node'
Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current darwin-x64 runtime: "npm install --platform=darwin --arch=x64 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
at Object.<anonymous>
The cross platform topic in the official documentation (https://sharp.pixelplumbing.com/install#cross-platform) didn't help. Tried to follow what they suggested, but kept getting the same error.
What did I do to solve it?
The Sharp package was originally installed in the Linux computer.
So, to add support to MacOS:
In the MacOS computer, ran npm remove sharp
In the MacOS computer, ran npm i sharp
That left me with 10 changed files: 5 of them removing Linux support, 5 of them adding MacOS support. I then discarded the removal of the 5 Linux files, and kept the addition of the 5 MacOS files, as the following image:
This way, I ended with support in the two platforms.
Hope this helps someone who needs it.

Node Canvas throwing error when running project

Node Canvas is not working for me on m1
When I try to run my project I get this error message:
Error: dlopen(.../node_modules/canvas/build/Release/canvas.node, 0x0001): tried: '.../node_modules/canvas/build/Release/canvas.node' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/canvas.node' (no such file), '/usr/lib/canvas.node' (no such file)
Already did:
brew install pkg-config cairo pango libpng jpeg giflib librsvg
xcode-select --install
npm i canvas
With no errors
Not sure how to debug this as there are people with Node Canvas working on m1 laptops, please help.
The most important thing is to make sure your Node executable has been compiled for Apple Silicon, meaning there's a pre-built binary for darwin-arm64. You can see which versions have which binaries here (the following page has the binaries for Node version 16.13.1): https://nodejs.org/download/release/v16.13.1/.
Node v14 has no pre-built binaries for darwin-arm64 (see https://github.com/nodejs/node/issues/36161), because it can't be compiled natively to Apple Silicon.
I use volta (https://volta.sh/) to manage my Node versions, so if you install Node v16 with volta install node#16 and then run npm i canvas, you should get a correctly compiled canvas.node file.
If that fails, go to node_modules/canvas and run npm install --build-from-source, which will compile the C++ addon and output the corect canvas.node.
You can check this by running:
file node_modules/canvas/build/Release/canvas.node
# outputs: node_modules/canvas/build/Release/canvas.node: Mach-O 64-bit bundle arm64
If it says arm64 at the end, then you're good to go. If it still says x86_64, then something went wrong.
I use npm install --build-from-source. It work!
But there are new mistakes
dlopen(.../node_modules/canvas/build/Release/canvas.node, 0x0001): symbol not found in flat namespace '_cairo_fill'

Upgrade from node6.x to node8.x gives "node-saas" binding errors

On windows 64 bit platform, upgrade from Node6.x to Node8.x gave the following
Error: Missing binding C:\bisbor1\src\main\webapp\node_modules\node-sass\vendor\win32-x64-57\binding.node
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 8.x
It also asks to build the node-saas library for which it is mandatory to install Python. For a front end developer, it seems a bit bizarre to install Python to run a simple "Hello Angular" app. And funnily, i don't even need node-saas. Its not a direct dependency for my application.
After breaking my head over installing Python to reinstalling "node_modules" several times (never mind the "download" of the internet that 'npm install' demands), I finally found peace with the following solution.
"Downloaded the appropriate platform specific binding file (note the version of binding in the error thrown) from the git repository
https://github.com/sass/node-sass/releases
And updated the node-sass binding in my npm cache which is located at C:\Users\bisbor1\AppData\Roaming\npm\node_modules\ng-packagr\node_modules\node-sass\vendor\win32-x64-57"
The Primary step is to ensure that you are having Python 2.7 installed, because node-gyp only supports python2, as of writing the post.
To do so:
check whether Python Version is 2.7 or lower using python --version
downgrade using sudo apt-get install python
then rebuild node-sass using npm rebuild-node-sass
If everything else is correct, then a npm start would launch your App.

Can't install opencv w/ npm

I'm trying to install the opencv package for a project I'm working on by running the following:
npm install opencv --save
However, every attempt at doing so results in this long list of errors
I've been at a loss with this for a while now, but I'm afraid it may be because I'm not very well versed in working with ubuntu/npm, so the answer may be obvious
Things to take into consideration:
I'm working in a public cloud9 workspace
Ubuntu 14.04.2
Node 4.1.1
npm 2.14.4
OP here. This ended up being multiple things.
the install instructions for OpenCV (help.ubuntu.com/community/OpenCV) reference outdated packages and therefore do not install properly, and if you're not watching it, you'll miss the fail messages, as the script attempts to continue despite the failed installs.
after you get the script to run & install successfully, you'll notice that it installs the latest version of OpenCV, 3.1.0 which is perfectly acceptable.
According to the .readme on the node-opencv github, You'll need OpenCV 2.3.1 or newer installed before installing node-opencv. you'll end up noticing this statement is partially untrue. In reality, you need any version between 2.3.1 and 2.4.11. Any version after 2.4.11 will result in a failed npm install

Installing nodejs and npm on WDMyCloud server

I'd like to install nodejs and npm on my WDMyCloud server, but I'm having problems doing so. The server itself is running Debian GNU/Linux 7 (wheezy).
I'm able to run sudo apt-get install nodejs without error, but upon running the command I'm presented with the following message:
nodejs: error while loading shared libraries: libcares.so.2: ELF load command alignment not page-aligned
And when trying to run sudo apt-get install npm, it doesn't successfully install:
The following packages have unmet dependencies:
npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
The WDMYCLOUD v4 firmware uses 64K pagesize (while v3 uses common 4k pagesize) to increase I/O speed. All softwares in the built-in Debian repository were built for 4k pagesize and are broken for use now. The error you saw exactly complained about that.
Refer to: https://community.wd.com/t/why-pagesize-64k-in-firmware-v4/94868
As workarounds, you can:
1. Build 64k softwares by your own (the ridiculous official suggestion)
2. Use some other people's reporsity (at your own risk). For me, I'm using https://community.wd.com/t/repository-with-software-worked-on-v4-firmware/94532. Its ffmpeg works well so far so good.
3. Downgrade the firmware to V3
Regarding Nodejs, I'm also a big fan of it but I didn't try out to build "it" by my own because it seems a lot of effort -- besides the nodejs and npm, we probably have to rebuild packages provided by npm. So I gave up on the cool idea of running nodejs on WDMYCLOUD.
If someone someday makes it, please let us know and we'd appreciate that!

Resources