node-canvas error

node-canvas error
Is there any other library I can use since `node-canvas` seems to be an issue, please recommend.
Is there any other library I can use since `node-canvas` seems to be an issue, please recommend.
I tried using node-canvas with jsbarcode to process barcode from a node application but node-canvas seems to be an issue ever since I tried implementing using it.I have tried rebuilding from source yet the error still a blocker.
node:internal/modules/cjs/loader:1302
return process.dlopen(module, path.toNamespacedPath(filename));
^

Error: dlopen(/Users/mac/node_modules/canvas/build/Release/canvas.node, 1): Library not loaded: @loader_path/libpixman-1.0.42.2.dylib
Referenced from: /Users/mac/node_modules/canvas/build/Release/canvas.node
Reason: no suitable image found. Did find:
/Users/mac/node_modules/canvas/build/Release/libpixman-1.0.42.2.dylib: cannot load 'libpixman-1.0.42.2.dylib' (load command 0x80000034 is unknown)
/Users/mac/node_modules/canvas/build/Release/libpixman-1.0.42.2.dylib: cannot load 'libpixman-1.0.42.2.dylib' (load command 0x80000034 is unknown)

Node.js v18.13.0
[nodemon] app crashed - waiting for file changes before starting…
node:internal/modules/cjs/loader:1302
return process.dlopen(module, path.toNamespacedPath(filename));
^

Error: dlopen(/Users/mac/node_modules/canvas/build/Release/canvas.node, 1): Library not loaded: @loader_path/libpixman-1.0.42.2.dylib
Referenced from: /Users/mac/node_modules/canvas/build/Release/canvas.node
Reason: no suitable image found. Did find:
/Users/mac/node_modules/canvas/build/Release/libpixman-1.0.42.2.dylib: cannot load 'libpixman-1.0.42.2.dylib' (load command 0x80000034 is unknown)
/Users/mac/node_modules/canvas/build/Release/libpixman-1.0.42.2.dylib: cannot load 'libpixman-1.0.42.2.dylib' (load command 0x80000034 is unknown)

Node.js v18.13.0
[nodemon] app crashed - waiting for file changes before starting…
4 Replies
Leke
LekeOP2y ago
const express = require('express');
const JsBarcode = require('jsbarcode');
const { createCanvas } = require('canvas');

const { handleErrors } = require('../helpers');

const router = new express.Router();

// Generate Barcode
router.get('/barcode', async (req, res) => {
const { data } = req.params;

try {
if (!data) {
return res.status(404).send();
}

const canvas = createCanvas(250, 100, 'image');
JsBarcode(canvas, data, {
fontSize: 24,
fontOptions: 'bold',
mod43: true,
});
const buffer = canvas.toBuffer();

res.set('Content-Type', 'image/png');
res.status(200).send(buffer);
} catch (e) {
handleErrors(e, res);
}
});

module.exports = router;
const express = require('express');
const JsBarcode = require('jsbarcode');
const { createCanvas } = require('canvas');

const { handleErrors } = require('../helpers');

const router = new express.Router();

// Generate Barcode
router.get('/barcode', async (req, res) => {
const { data } = req.params;

try {
if (!data) {
return res.status(404).send();
}

const canvas = createCanvas(250, 100, 'image');
JsBarcode(canvas, data, {
fontSize: 24,
fontOptions: 'bold',
mod43: true,
});
const buffer = canvas.toBuffer();

res.set('Content-Type', 'image/png');
res.status(200).send(buffer);
} catch (e) {
handleErrors(e, res);
}
});

module.exports = router;
Daryl
Daryl2y ago
This option could be interesting, I haven't use it though: https://github.com/Brooooooklyn/canvas
GitHub
GitHub - Brooooooklyn/canvas: High performance skia binding to Node...
High performance skia binding to Node.js. Zero system dependencies and pure npm packages without any postinstall scripts nor node-gyp. - GitHub - Brooooooklyn/canvas: High performance skia binding ...
Daryl
Daryl2y ago
On the other hand, the error could be related to your Node version.
Leke
LekeOP2y ago
Honestly when i deployed the runs smoothly on my server Works fine on my remote sever
Want results from more Discord servers?
Add your server