TypeError: options.Canvas is not a constructor
See original GitHub issueI am running node, and am attempting to merge two images with this code:
const mergeImages = require('merge-images');
const Canvas = require('canvas');
mergeImages(["img1.png", "img2.png"],
{
Canvas: Canvas
})
.then(b64 => function()
{
//Do stuff
});
However, the above gives an error:
(node:19271) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: options.Canvas is not a constructor
I saw this, but after changing my code to const Canvas = require('canvas').Canvas;
, like was suggested, I got another error:
TypeError: Image is not a constructor
Like was suggested in the issue above, I tried downgrading to canvas 1.6.13, but that resulted in:
ReferenceError: window is not defined
Not sure if it’s me, merge-images. or canvas that’s causing the issue.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:33 (9 by maintainers)
Top Results From Across the Web
TypeError: CanvasRenderService is not a constructor
Either downgrade your chartjs-node-canvas version 2.x.x or update your code according to new version. ... ChartJSNodeCanvas(options).
Read more >TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >canvas-constructor
canvas -constructor. An ES6 chainable class for node-canvas with built-in utilities. npm Total alerts GitHub license. Support Server ...
Read more >canvas-constructor - npm
A ES6 class for node-canvas with built-in functions and chained methods.. Latest version: 7.0.0, last published: 4 months ago.
Read more >[Solved]-TypeError: SnakeGame is not a constructor-discord.js
Coding example for the question TypeError: SnakeGame is not a constructor-discord.js.
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
It should help:
@lukechilds hello , everyone I have faced this issue and saw the code , the solution is you have to 1- require
const Canvas = require('canvas');
2- pass the Canvas as option like{Canvas: Canvas}
3- go to a file called index.umd.js into the node_modules/merge-images/… and make this changenew options.Canvas.Canvas()
at line 25 insteadnew options.Canvas()
thanks,