html2canvas: TypeError: html2canvas.default is not a function
- 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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 22
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”
For me the problem was I’m using TypeScript and the
node_modules\html2canvas\dist\types\index.d.tsfile is incorrect. It says that they are exporting html2canvas as the default exportexport default html2canvas;. This is untrue.I had to use any to get around this as follows:
Facing this error for html2canvas version : 1.0.0-rc.3
using with react 15, typescript, along with SPFX framework. #1440
@niklasvh , kindly please check why this is happening?
I was able to resolve the ‘not a function’ error that is throw when trying to call
html2canvas(element, options). I have similar setup to @JEEVANJGA, using react 15, typescript, and SPFX. After downloading the @types for the module the index.d.ts file looks like this originally:import { CloneOptions } from './dom/document-cloner';import { ResourceOptions } from './core/cache-storage';import { RenderOptions } from './render/canvas/canvas-renderer';export declare type Options = CloneOptions & RenderOptions & ResourceOptions & {backgroundColor: string;foreignObjectRendering: boolean;logging: boolean;removeContainer?: boolean;};declare const html2canvas: (element: HTMLElement, options?: Partial<Options>) => ``Promise<HTMLCanvasElement>;export default html2canvas;If you change the last line to:
export = html2canvas;and import the module like this:
import * as html2canvas from 'html2canvas';it no longer throws an error.
Hope this helps someone.
Got the same issue, @dharnen solution helped.
It did the trick for me.
Happens for me too!
I am on angular/cli: 1.7.2