image-palette icon indicating copy to clipboard operation
image-palette copied to clipboard

Uncaught TypeError: Canvas is not a constructor

Open nicmosc opened this issue 7 years ago • 0 comments

This is an issue with image-palette-core. I'm working with react-image-palette, that is itself using [email protected].

I'm running an electron app, and while I'm using the library in the render process (where we have access to all the common browser features) the following:

if (!!process && process.execPath) {
    iAmOnNode = true;
}

Is truthy since we're running an electron app which uses node. Not sure why the lines following, i.e.

// if (iAmOnNode) {
//   Canvas = require('canvas');
//   Image = Canvas.Image;
//   fs = require('fs');
// }

Are commented out. Now I think mine is more of an edge case where Electron causes the statement to be truthy, so I'll probably have to fork the library and make changes for my particular case (this lib is awesome btw).

Just wondering if it's maybe better to remove either the if statement since that will cause the error to be thrown, since canvas will be undefined, and not support a node environment at all. Or put back the canvas dependency.

Thanks

nicmosc avatar Nov 29 '18 14:11 nicmosc