Dom-to-image: Angular 2 project: Not working on Windows, works on Mac

Created on 8 Nov 2017  ·  1Comment  ·  Source: tsayen/dom-to-image

Use case: description, code

I am using this library but upon calling the "toBlob" method I get an error saying "domtoimage" is undefined.

I have imported it using
npm install dom-to-image

and then

import domtoimage from 'dom-to-image';

Usage:

domtoimage.toBlob(this.posterFinal.nativeElement)
        .then((blob) => {
          filesaver.saveAs(blob, 'Student-Talks-poster.png');
        });

One note: I am calling it from within a setTimeout() which might affect some things? I am not sure. However, the exact same code works on my Mac with Chrome.

Expected behavior

Download the blob as an png.

Actual behavior (stack traces, console logs etc)

Doesn't download because of this error:

core.es5.js:1020 ERROR TypeError: Cannot read property 'toBlob' of undefined
    at eval (graphics-builder.component.ts:163)
    at ZoneDelegate.invokeTask (zone.js:425)
    at Object.onInvokeTask (core.es5.js:3881)
    at ZoneDelegate.invokeTask (zone.js:424)
    at Zone.runTask (zone.js:192)
    at ZoneTask.invokeTask (zone.js:499)
    at ZoneTask.invoke (zone.js:488)
    at timer (zone.js:2040)

Library version

+ [email protected]

Browsers

  • [61] Chrome 49+

Most helpful comment

Wait I got it to work!

Changed this:

import domtoimage from 'dom-to-image';

To this:

import * as domtoimage from 'dom-to-image';

>All comments

Wait I got it to work!

Changed this:

import domtoimage from 'dom-to-image';

To this:

import * as domtoimage from 'dom-to-image';
Was this page helpful?
0 / 5 - 0 ratings

Related issues

AbuSufyan picture AbuSufyan  ·  7Comments

piyushSinghalDemo picture piyushSinghalDemo  ·  8Comments

rhmg picture rhmg  ·  9Comments

cnatis picture cnatis  ·  8Comments

yangqin007 picture yangqin007  ·  3Comments