Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →The error html2canvas_1.default is not a function usually means your Angular bundle imported html2canvas with a default-import shape that does not match the module exported by the installed package. It is an import/export mismatch—not, by itself, a failure to draw the canvas. Check your html2canvas version, TypeScript interop settings, and generated module format, then use the import form that matches them.
What the error means
At runtime, the compiled code is trying to call a value reached through html2canvas_1.default, but that value is not a function. The source line may look reasonable while the generated bundle expects a default export that the installed module does not expose in that form.
This can surface after changing Angular CLI, TypeScript, bundler, or html2canvas versions because those pieces affect how imports are compiled and how package exports are interpreted. The html2canvas maintainer issue #1440 records this exact error after an Angular CLI upgrade; it was opened on February 15, 2018. That example identifies a possible trigger, not a claim that every occurrence has the same cause.
Keep the distinction clear: this particular message points first to the imported value’s shape. If changing the import makes the call work but some images or fonts are absent, that is a separate rendering or cross-origin problem.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
Choose the import that matches your module setup
Try the import form supported by the html2canvas package and the compiler configuration in this project. Do not use both forms together, or force a cast to any merely to silence a TypeScript error: those workarounds can hide the mismatch without making the runtime value callable.
CommonJS-style output: try a namespace import
For a CommonJS-style package build or older compiler interop setup, try importing the module namespace:
import * as html2canvas from 'html2canvas';
html2canvas(element).then(canvas => {
// use canvas
});
This form is appropriate only if the installed package and toolchain produce a callable namespace value in the project’s runtime. In TypeScript’s module model, a namespace import represents an object with exports as properties; it is not universally interchangeable with a default import. If TypeScript reports that the namespace is not callable, do not work around that diagnostic with a cast: use the package’s supported default-export form and compatible compiler settings instead.
Rank #2
Default export: use it when the package and compiler support it
If the installed html2canvas version exposes a true default export and your Angular/TypeScript configuration handles it accordingly, use:
Free tools Windows power users keep installed
One-click scans. No signup required.
import html2canvas from 'html2canvas';
html2canvas(element).then(canvas => {
// use canvas
});
Default imports bind the module’s default export. A default import is therefore correct when that export exists and the compiler/bundler interop produces the expected runtime value—not simply because it is shorter or because another project’s code uses it.
Diagnose the mismatch before changing more code
Use the package version, compiler configuration, and emitted bundle as a set. Changing only the Angular source import may not resolve a mismatch caused by a package or build configuration change.
- Check which package is installed. Inspect
package.jsonand the lockfile for the html2canvas version actually resolved. If the dependency is absent, add it using the package manager and version policy already used by the project; avoid installing a second copy or guessing that the newest release is compatible with your setup. - Record the toolchain versions. Note the Angular CLI and TypeScript versions along with the html2canvas version. When the problem began after an upgrade, compare those records with the last working build. This helps isolate whether a package update, compiler change, or CLI/bundler change altered the import shape.
- Inspect TypeScript interop settings. Review the project’s active
tsconfigfiles and determine which one the Angular build uses. Check the module and interop options relevant to the installed package; do not change settings blindly, because a setting appropriate for one module format may affect other imports. - Try the compatible import form. If the current default import reaches a non-callable
.defaultat runtime and the package is being handled as CommonJS, test the namespace form. If TypeScript says that namespace is not callable, use the supported default export with compatible compiler settings rather than suppressing the error. - Rebuild after the edit. Stop and restart the Angular development server so the changed import is compiled into a fresh bundle. Confirm the rebuilt application loads the component and reaches the capture call.
- Check where the code runs. Call html2canvas only in a browser, after the target element exists. Keep it out of server-side rendering and Node execution paths.
- Separate import success from image completeness. If the function now runs but cross-origin images or fonts are missing, investigate browser same-origin and CORS rules. That symptom is not proof that the import remains wrong.
Capture an Angular element after it exists
html2canvas is a browser-side DOM renderer. Its documented call is html2canvas(element[, options]); it returns a Promise containing a canvas element. In an Angular component, select a real DOM element after Angular has rendered it, then handle the returned Promise.
import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core';
import html2canvas from 'html2canvas';
@Component({
selector: 'app-report',
template: `
<section #report>
<h2>Report</h2>
<p>Content to capture</p>
</section>
<button type="button" (click)="capture()">Capture</button>
`
})
export class ReportComponent implements AfterViewInit {
@ViewChild('report') report!: ElementRef<HTMLElement>;
ngAfterViewInit(): void {
// The report element is available after the view has initialized.
}
capture(): void {
const element = this.report?.nativeElement;
if (!element) return;
html2canvas(element).then(canvas => {
document.body.appendChild(canvas);
}).catch(error => {
console.error('Could not render the report:', error);
});
}
}
The import in this example assumes the package and compiler support the default-export form. If your diagnosis indicates a CommonJS-style namespace import is required, change the import to the namespace version shown above; do not combine the two. The sample appends the resulting canvas to the document so the output is visible. In a real component, you can instead display it in your own UI or use the browser’s canvas APIs to export it.
For a minimal browser check independent of Angular, the documented pattern is:
Rank #4
html2canvas(document.body).then(function(canvas) {
document.body.appendChild(canvas);
});
If this browser-only example works under the same dependency and build setup, but the Angular code does not, check when the Angular element is created and which execution path calls the function. If the simple call fails with the same runtime message, return to the module-shape diagnosis.
What fixing the import does—and does not—solve
It does not make html2canvas a native screenshot
html2canvas reconstructs an image by reading DOM elements and the styles applied to them. It is not a native browser screenshot, so it may not reproduce every CSS property exactly. A successful Promise confirms that a canvas was produced; it does not guarantee a pixel-for-pixel image of the browser viewport.
It does not remove browser-origin restrictions
Cross-origin content can be unavailable to the renderer under browser security rules. The html2canvas project documentation notes that cross-origin content requires a proxy to bring that content to the same origin. If the canvas is created but external images or fonts are missing, investigate their origins and the relevant CORS setup rather than cycling through import syntax.
Recommended Free Tools
Best Value
It does not make the package suitable for Node.js
The project describes html2canvas as heavily browser-dependent and not suitable for Node.js. Do not call it from an Angular server-rendering path, a Node script, or code that runs before a browser DOM and target element exist. Keep browser-only capture behind a client-side lifecycle point or user action.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting by symptom
| Symptom | Likely area to check | Next action |
|---|---|---|
html2canvas_1.default is not a function |
The compiled default binding does not resolve to a callable function. | Check html2canvas version and interop configuration; test the compatible import form and rebuild. |
| TypeScript says the namespace import is not callable | The namespace import is modeled as an object, or the package/toolchain expects a default export. | Use the package-supported default export with compatible compiler settings. Do not force any. |
| The error appeared after an Angular CLI or dependency upgrade | A changed package version, module format, or compiler/bundler output may have changed interop behavior. | Record the Angular CLI, TypeScript, and html2canvas versions; compare the lockfile and active tsconfig with the last working build. |
| The call runs before the element exists | The target is queried too early or the code executes outside the browser view lifecycle. | Use the element after Angular has rendered it, for example after view initialization or from a later user action. |
| The call succeeds, but images or fonts are missing | Browser same-origin/CORS restrictions or DOM/CSS rendering limits. | Check cross-origin access and proxy requirements; do not treat missing assets as an import error. |
| The code fails during SSR or in Node | html2canvas depends on browser DOM behavior. | Move the capture into browser-only code; the project does not describe the library as suitable for Node.js. |
Or skip the browser setup
If your actual task is capturing a public webpage—not rendering an Angular component’s live DOM—ScreenshotNeo can return a screenshot or PDF through one GET request. It is a separate approach, not a fix for an incorrect html2canvas import, and it cannot capture an arbitrary in-memory Angular element. ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server gives AI agents screenshot tools, and the free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000.
For example, save a webpage screenshot as WebP with cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options and response details. Start with ScreenshotNeo if a hosted website capture fits your task, or sign up for 1,000 free screenshots a month with no card.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsFrequently Asked Questions
Does changing the import convert an Angular element to a PDF?
No. The import fix only makes the html2canvas function callable. The documented result is a canvas; PDF creation requires a separate step or tool.
Can html2canvas capture a URL from a Node script?
The html2canvas project describes the library as browser-dependent and not suitable for Node.js. For a webpage URL rather than a live browser DOM element, use a browser-based screenshot service instead.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

