I am using webpack. when import html2canvas, I got following warning:
WARNING in ./~/html2canvas/dist/html2canvas.js
Critical dependencies:
8: 484-491 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get beter results.
Yeah, same warning.
It would be great if npm package had source code, not only prebuilt files. So we could import
from the source with webpack
Certainly not _the_ solution, but I did the following:
npm uninstall html2canvas
..npmignore
and remove the line with src/
.package.json
and change "main": "dist/html2canvas.js"
to "main": "src/core.js"
.npm install --save /path/to/repo
.No change to your existing code is required.
Until a better solution exists, this works for me. It silences the warnings and yields a better optimized bundle.
Yeah, that's one way to fix it. It is not very handy for my build process though. I added html2canvas
as noParse
to webpack config file
module: {
noParse: [/html2canvas/, ]
},
Hope this issue would be fixed so I could remove it.
@brabadu Thanks for the solution. Can I ask a question?
How do you go about import html2canvas using es6 import syntax? Is it possible?
@uriklar Sure, this works for me
import html2canvas from 'html2canvas';
html2canvas(document.body).then(...)
Indeed it works :-) silly me, digging into source code instead of trying the obvious...
Thanks you very much!
As @basilfx said, the maintainers should declare the library index on their package.json. Since they published it on npm, they should treat the library as a module.
Most helpful comment
Yeah, that's one way to fix it. It is not very handy for my build process though. I added
html2canvas
asnoParse
to webpack config fileHope this issue would be fixed so I could remove it.