Sgt1503 / Vaadin-HTML2CANVAS

Other
1 stars 1 forks source link

ReferenceError: require is not defined #2

Closed ZhukovAlV closed 1 year ago

ZhukovAlV commented 1 year ago

VAADIN (version 23.2.7)

When start application error: Vaadin development mode initialized ReferenceError: require is not defined

The problem is in the file: html2canvas-loader.js

I read about this problem here: https://github.com/vaadin/flow/issues/14477

I try code:

let html2canvas;
let blobValue;
window.html2canvas = require('html2canvas');
window.blobValue = 1;

change to:

import * as html2canvas from 'html2canvas';
let blobValue;
window.html2canvas = html2canvas;
window.blobValue = 1;

But then I got another error :( TypeError: html2canvas is not a function

ZhukovAlV commented 1 year ago

I'm sorry, I found how to write import in file html2canvas-loader.js

import html2canvas from 'html2canvas';

let blobValue;
window.html2canvas = html2canvas;
window.blobValue = 1;

In this case, everything will work. Thank you for your project

mstahv commented 1 year ago

That seems to fix it for me too. Tested in Chrome and Safari. Safari bugs, but I guess it is like that in previous versions as well. Created a PR to fix it. Cool Add-on BTW!