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: html2canvas.default is not a function

See original GitHub issue
  • You are using the latest version
  • You are testing using the non-minified version of html2canvas and checked any potential issues reported in the console

Bug reports:

Simple Call:

html2canvas(document.getElementById('passport-questions-form')).then(canvas => {
    // code...
});

Is giving me: ERROR TypeError: html2canvas_1.default is not a function

This happened after upgrading Angular cli@1.6.8 from 1.5.0. I assume it might be because there was a TypeScript Update?

  • html2canvas version tested with: alpha.10
  • Browser & version: chrome:64.0.3282.167
  • Operating system: windows 10

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:21

github_iconTop GitHub Comments

21reactions
dbonillaocommented, Jun 22, 2018

Make sure to import the script under the scripts list in angular-cli.json “scripts”: [ “…/node_modules/html2canvas/dist/html2canvas.min.js” ]

And in the class as:

import * as html2canvas from “html2canvas”

5reactions
DanLatimercommented, Nov 14, 2019

For me the problem was I’m using TypeScript and the node_modules\html2canvas\dist\types\index.d.ts file is incorrect. It says that they are exporting html2canvas as the default export export default html2canvas;. This is untrue.

I had to use any to get around this as follows:

import * as html2canvasWrong from "html2canvas"
var html2canvas = html2canvasWrong as any as (element: HTMLElement, options?: Partial<html2canvasWrong.Options>) => Promise<HTMLCanvasElement>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular: ERROR TypeError: html2canvas_1.default is not a ...
html file. I have a downloadPDF() function in app.component.ts. My goal is : when the .ts file is loaded, its constructor will ...
Read more >
Angular 5 error: html2canvas_1.default is not a function #1561
I downloaded the latest version and lazy loaded the js file on my component which is showing when i go to inspect element->...
Read more >
TypeError: $(...).html2canvas is not a function - Drupal
Hi, I found TypeError: $(...).html2canvas is not a function while using html2canvas function in my custom jquery.
Read more >
A brand new website interface for an even better experience!
TypeError : html2canvas.default is not a function.
Read more >
jspdf npm, html2canvas_1 default is not a function, jspdf ...
To render an element with html2canvas, simply call: html2canvas(element[, options]); The function returns ... typeerror t charcodeat is not a function jspdf.
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