bubkoo / html-to-image

✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
MIT License
5.79k stars 544 forks source link

typeerror: assignment to constant variable #306

Open jianxinliu opened 2 years ago

jianxinliu commented 2 years ago

An "typeerror: assignment to constant variable" error occurred after the project was builded with Webpack 3.6.0. While running on the development mode everything is ok.

Additional Context

code after build image

source code: image

the code after build extract the function checkCanvasDimensions as plain code,which is the cause of the problem.

dist from npm: image

Your Environment

I wonder if this is a bug of Webpack? And What should I do?

biiibooo[bot] commented 2 years ago

👋 @jianxinliu

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

ctool-lenggi commented 2 years ago

I had this morning also this error message. Thanks @jianxinliu for the hint with the skipAutoScale reference.

Workaround: Set skipAutoScale to true. htmlToImage.toPng(node, { skipAutoScale: true })

jianxinliu commented 2 years ago

I had this morning also this error message. Thanks @jianxinliu for the hint with the skipAutoScale reference.

Workaround: Set skipAutoScale to true. htmlToImage.toPng(node, { skipAutoScale: true })

Thanks @ctool-lenggi ‘s suggestion. We just change the source code as a temporary solution, but now I'd rather choose yours.

image

As the source code shows, set skipAutoScale: false will check width and height of the canvas avoid exceeding the maximum limit of canvas which is 16384 pixels. It is large enough for my project, so i choose set skipAutoScale: true to avoid reassign to a constant variable after build.

image

image

btw, what can i do if my project requires skipAutoScale: false?