Html2canvas: warning in using webpack in 0.5.0-alpha

Created on 14 Dec 2015  路  9Comments  路  Source: niklasvh/html2canvas

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.

Most helpful comment

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.

All 9 comments

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:

  • If installed, remove it using npm uninstall html2canvas.
  • Clone this repository to a local folder
  • Edit .npmignore and remove the line with src/.
  • Edit package.json and change "main": "dist/html2canvas.js" to "main": "src/core.js".
  • Install package using 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.

Was this page helpful?
0 / 5 - 0 ratings