question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: options.Canvas is not a constructor

See original GitHub issue

I 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:open
  • Created 5 years ago
  • Reactions:4
  • Comments:33 (9 by maintainers)

github_iconTop GitHub Comments

11reactions
weekendchallengescommented, May 30, 2019

It should help:

const {Canvas,Image}=require('canvas');
Canvas.Image=Image;
3reactions
niypoocommented, Mar 12, 2019

@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 change new options.Canvas.Canvas() at line 25 instead new options.Canvas() thanks,

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found