niklasvh / html2canvas

Screenshots with JavaScript
https://html2canvas.hertzen.com/
MIT License
30.11k stars 4.75k forks source link

html2canvas is not a function at HTMLDivElement.<anonymous> #3099

Open MariusGhinea opened 11 months ago

MariusGhinea commented 11 months ago

Hi, using the latest version of html2canvas.js here, in the latest Chrome browser, under Linux.

I am getting the message in the title whenever I try to use html2canvas:

exportArea.addEventListener('click', e =>{

html2canvas(document.querySelector('#tablesArea')).then(canvas => {

    let canvasUrl = canvas.toDataURL();

    console.log(canvasUrl);

});

});

I presume that I do not really import html2canvas, although I have written this at the start of my js script, and html2canvas.js is in the same folder as the projname.html and projname.js are:

import * as html2canvas from './html2canvas.js';

I also wrote this in the html file:

In order to use the html2canvas.js file I had to disable JS source maps and CSS source maps, or Chrome would throw a map related error. If I was using the .min.js I would not get the map related error, but it seems that I have to use the non-min latest ver of html2canvas?... Anyway, even if I use the .min.js version of the module I still get the "html2canvas is not a function " error.

I am a complete noob, but I have grinded this problem for a whole day without any result - and google searches did not provide me with a wealth of info regarding this problem, sadly. Please help, I am at my wits end, I cannot understand why this does not work.

MariusGhinea commented 11 months ago

please, anyone, can you tell me how to import html2canvas? a little advice, please, how do I import html2canvas module? I tried importmaps and either I do not understand how to use importmaps or whatnot, but it still does give the same error plus the DevTools failed to load source map: Could not load content for https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.js.map .what is the problem? FFS, this is not arcane magic, is something that someone could help me with, please, I am not a lazy bum, I am giving my best to understand and learn but I do not get it, how to import html2canvas? It is already the second day of nothingness for me, over and over effin my brain with what should be elementary.