-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jsPDF 2.0.0 - Critical dependency: the request of a dependency is an expression #2846
Comments
jsPDF displays a warning when ng-serving: "Critical dependency: the request of a dependency is an expression". An issue has been reported about it: parallax/jsPDF#2846
I can add that also we found the below lines. [ng] WARNING in ./node_modules/jspdf/dist/jspdf.umd.min.js 195:141-151 |
+1 |
Thanks for the elaborate issue report. The reason is probably how we load the optional libraries like html2canvas now. We should probably inline the code in loadOptionalLibrary so the import is no longer an expression. If your code works, you can probably just ignore the warning for now. You might also try #2839 (comment) |
+1 |
1 similar comment
+1 |
@HackbrettXXX What if it doesn't ? 😛 My current issue is trying to make a PDF from HTML, and I'm getting errors from dompurify / html2canvas (tried both with HTML element and string). Copied the example from the documentation, just changed the element: import { jsPDF } from 'jspdf'
(...)
// triggered on button click
getPdf() {
const pdf = new jsPDF()
pdf.html(document.getElementById('report'), {
callback: function (doc) {
doc.save()
},
})
pdf.html(document.getElementById('report').innerHTML, {
callback: function (doc) {
doc.save()
},
})
} Also tried using import * as jsPDF from 'jspdf'
const pdf = new jsPDF.jsPDF() for testing sake, with no luck I'm running Could it be related to this issue ? |
@Ribeiro-Tiago I'm currently digging into that. Seems like build tools don't like expressions as imports. I hope I can publish a new release with a fix soon. As workaround you can try to include the UMD variant of jsPDF as script tag and ignore the warning. |
Same here
Code:
|
@HackbrettXXX my issue is not the warning per se, but the errors. Still happening with including as script tag. Could it be caused by some vue's webpack config ? Shall I open a new issue for this ? |
@Ribeiro-Tiago I'm pretty sure it's the same issue. I tested it yesterday with an Angular project. I got the warning and code that uses one of the optional libraries does not work. I'm pretty sure the warnings/errors are the same for Vue. |
@HackbrettXXX oki, do you have an ETA on when you might have some time to release a fix ? |
I hope next week. |
Same warning. I am waiting next release. :) |
- inline loadOptionalLibrary code - remove "browser" field in pacakge.json so tools will prefer the es variant - update Optional Dependencies section in readme - fix rollup config fix parallax#2846
@RegniBlef could you check if the pull request #2865 really fixes the issue? |
Getting the same error on an Angular project with the following snippit:
Dependencies:
Error message:
|
* fix "dependency is an expression" issue - inline loadOptionalLibrary code - remove "browser" field in pacakge.json so tools will prefer the es variant - update Optional Dependencies section in readme - fix rollup config fix #2846 * add missing file extensions to imports
Was going to try with the branch you mentioned earlier but saw that you just merged it to master so tried with master (cloned locally, ran |
Good to hear. Thanks. I will prepare a new release next week. |
Hi, I don't if this is really relevent, but just for those who are struggling with this issue (because it blocks indeed the PDF generation), just install version jsPDF 1.5.3, works like a charm. Just in case, I'm currently making PDFs in a VueJS app, using [email protected] and html2canvas 1.0.0-rc.7. |
@HackbrettXXX Also just tried it and found no initial problems. Thanks for the good work. |
working. install
|
@e-hop or |
If using yarn you can pin jspdf version to ^2.1.0 in your project's package.json for temporary fix.
|
That's a bit strange, I still have the issue after upgrading to 2.1.0, do you know why ? Here is my code let doc = new jsPDF("p", "pt", "a4")
doc.html("<div><h3>Test</h3></div>", {
callback: function (d) {
d.output("dataurlnewwindow")
},
}) with my package.json "dependecies: {
"jspdf": "^2.1.0",
"dompurify": "^2.0.12",
"html2canvas": "^1.0.0-rc.7",
} error:
|
@petitmat Which framework build tool do you use? Is the dompurify chunk in the dist folder? Any warnings during the build? Is dompurify correctly installed (check the node_modules folder)?. |
@HackbrettXXX thank you for your answer |
That's odd. Could you share a small repro project? |
Hope this will this will help, below resolved the issue during the build phase and dev:
For both the electron warnings and the jspdf warnings appear to be resolved. |
@staniszmatt this looks like you're importing jsPDF "twice" - once as script tag (or similar, don't know how electron works in particular) and once with import statements. If that's the case you can get rid of the script tag and the externals declaration. |
I also get an errors from webpack, using jspdf In my webpack.config.js please give some solutions |
@jaiho8816 please see #3356. |
For rollup add Docs: https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency |
Packages:
Node: 10.14.2
Angular: 10.0
jsPDF: 2.0.0
Problem:
I just updated jsPDF from 1.5.3 to 2.0.0 in my Angular 10.0 project and suddenly experience following warning during building:
Usage:
The text was updated successfully, but these errors were encountered: