Canvas node not working
See original GitHub issueI have a code which it seems the same as your example page
const mergeImages = require('merge-images');
const Canvas = require('canvas');
const sendMerged = function(email) {
mergeImages(['../public/logo.png', '../public/710fb.png'], {
Canvas: Canvas
})
.then //....
But I get the error
TypeError: options.Canvas is not a constructor
at /Users/xxx/GIT/projects/abc/node_modules/merge-images/dist/index.umd.js:25:32
If I console log Canvas I have the following
{ Canvas: { [Function: Canvas] _registerFont: [Function: _registerFont] },
Context2d: [Function: CanvasRenderingContext2D],
CanvasRenderingContext2D: [Function: CanvasRenderingContext2D],
CanvasGradient: [Function: CanvasGradient],
CanvasPattern: [Function: CanvasPattern],
Image: { [Function: Image] MODE_IMAGE: 1, MODE_MIME: 2 },
ImageData: [Function: ImageData],
//...
}
So I tried to change the code above to
//...
const Canvas = require('canvas').Canvas; //This is against the canvas documentation example
//...
After this change it seems to be fine with the constructor but it fails the line after with
TypeError: Image is not a constructor
at /Users/xxx/GIT/projects/abc/node_modules/merge-images/dist/index.umd.js:39:13
I wonder if it’s a bug with the new version of a dependency (I noticed you don’t pin them). Do your test run a new npm install? is this functionality tested? Thanks a lot
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
error canvas.node · Issue #2039 - GitHub
I use macOS Monterey 12.4,I have been troubled in the same issue all day ,trying to find an solution here and there ,but...
Read more >30 - Stack Overflow
I had the same problem. The issue was that the install script for node-canvas never got executed, which is why the build folder...
Read more >How to fix an issue installing Node `canvas` on macOS
I wanted to use the Node.js canvas NPM package but running npm install canvas failed with messages like this:
Read more >npm package canvas not working - Replit
As the title says I'm trying to use the canvas package. But when I run the code It gives me this: I expected...
Read more >canvas node module and Google Cloud Functions [38478412]
Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for your work @TobiTenno but I think merge-images should just be updated to work with
canvas@2
rather than patchcanvas@2
to expose acanvas@1
compatible API.canvas@2
has been out for a while now so support forcanvas@1
can be dropped.Sounds smart, we cannot guarantee that that api will be the final 2.x 👍