-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PDF export does not work when using ES6 modules import #59
Comments
It really depends on how the functionality is loaded: |
Doesn't work with either approach in the test case. |
Hhm, this is interesting, for some reason, jsPDF gets loaded as RGBColor... |
Isnt't this the same problem as in yWorks/jsPDF#12 |
Kind of similar, yes ;) I'm currently investigating it. Sadly, removing the named defines is not enough. |
To fix this once and for all, the build should be adjusted to get rid of the multiple (named or unnamed) defines. However using "import" on the original sources might be an option. The minified sources are not ES6 compatible but are meant to be script-imported (or maybe AMD). What loader are you using that doesn't work? Is it webpack or browserify or is that the browser ES6 loader implementation? |
For the es6 imports I use Webpack like with @fskpf's sample project. This works now when getting rid of
However, with the new build script from MrRio, the AMD require doesn't work properly anymore: require([
'svg2pdf.js/dist/svg2pdf.min.js',
'jsPDF/dist/jspdf.min.js'
], function (svg2pdf, jsPDF) {
// here jsPDF is an object with "default", "rewire" and "restore" properties
// "default" is jsPDF
} I suppose the reason is the generated UMD header, that uses the AMD -> CommonJS wrapper: define(["exports"], function(exports) {
// ...
exports.default = jsPDF;
var _default2 = exports.default;
function rewire($stub) {
exports.default = $stub;
}
function restore() {
exports.default = _default2;
}
exports.rewire = rewire;
exports.restore = restore;
Object.defineProperty(exports, '__esModule', { value: true });
}) |
Using We could only replace those during the build step. |
So the "new build script" broke it again? Which issue or commit is that? |
On our side: yWorks/jsPDF@21df1eb |
On their side: |
That looks like a huge mess to me. However the "node" part might be interesting. They are building a node compliant version that might work in an ES6 import case. |
The node version doesn't even run on node :D |
Ok, so I guess we have three options:
|
Do what suits you the most - the node versions would not work for us anyway with the SVG DOM not being available on node, as far as I can tell. If fixing is simple, go ahead. If you want to redo the thing using a more modern approach (I guess this is what they tried), feel free to write a new one. Maybe @fskpf wants to help? |
(see svg2pdf issue yWorks/svg2pdf.js#59)
Fixed it now for es6: yWorks/jsPDF@2f18d0f For AMD, it seems to be necessary to insert something like: jsPDF = jsPDF['default'] Seems to be the drawback, when es6 support is also wished. |
Yes - as soon as both default and named exports are used, rollup will even warn about this:
|
Please support ES6 modules import, thx. |
Did not release a version.
|
You installed the wrong jsPDF:
|
The fix for es6 imports will come with 2.0.1 |
Importing jspdf-yworks and svg2pdf.js as ES6 modules does not work. The jsPDF instance is missing functionality and calling svg2pdf on it will result in an excpetion:
However, when loading the very same svg2pdf and jspdf files via script-tags (directly from /node_modules/), the export works as expected. Thus I assume there is something broken with the ES6 import.
I've attached a sample project with webpack and ES6 modules import. To reproduce run
and open /dist/index.html. Then check the DevTools for the exception:
es6-modules-test.zip
The text was updated successfully, but these errors were encountered: