parallax / jsPDF

Client-side JavaScript PDF generation for everyone.
https://parall.ax/products/jspdf
MIT License
29.2k stars 4.67k forks source link

TypeError: default.a.convert is not a function #3315

Closed gupnee81 closed 2 years ago

gupnee81 commented 2 years ago

Hi, I am facing an issue with the latest version of jspdf in the react project.

This is an error that I am getting in the console.

jspdf.es.min.js:128 Uncaught (in promise) TypeError: _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default.a.convert is not a function
at new t (jspdf.es.min.js:128)

And, here is a code snippet using the latest version -

image image

I tried adding the below packages as external in the webpack, which also didn't help.

canvg, html2canvas, dompurify

Also, the same code snippet works when I downgraded the version to 2.3.1.

Pls, suggest if there is something I am missing as I am aiming to use the latest one.

Thanks

grimunit commented 2 years ago

I also got this snippet to work by downgrading to 2.3.1, my project is with Vue (2.6) and Webpack (3.6.0)

HackbrettXXX commented 2 years ago

Please provide a complete project so we can reproduce the issue.

MathiasOsterkamp commented 2 years ago

I also had this problem, it is caused by Webpack 3 and Babel missing dependencies, i think. Inside the dist files it remains still the import.

jspdf.es.js

import _typeof from '@babel/runtime/helpers/typeof';

Solution for me I created a fork with modified build.

.babelrc.json

{ "presets": [ [ "@babel/env",

  {
    "exclude": ["@babel/plugin-transform-typeof-symbol"]
  }
]

],

"exclude": ["node_modules/**"] }

michaelolson1996 commented 2 years ago

I am currently having this issue, I am on the current version and have tried downgrading as well as adding the .babelrc.json file to my root project folder. Any updates to a resolution?

nikhil-varma commented 2 years ago

Any update on the resolution for this?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

davidbarman commented 2 years ago

Any updates on how to fix this problem?

shehabadel commented 2 years ago

Any updates folks?

astiwz commented 2 years ago

getting same issue after npm audit in react for jspdf

astiwz commented 2 years ago

i was getting same issue, i updated npm package react-scripts from ^2.1.3 to 5.0.1, and now it is working.

SLC-GitHub commented 1 year ago

I have the same issue exporting html in Vue project ("vue": "^2.5.11",) with webpack("webpack": "^3.6.0",) "html2canvas": "^1.4.1", "isomorphic-dompurify": "^1.8.0", "jspdf": "^2.5.1", a pice of code to export: `const doc = new jsPDF({ orientation: 'l', }); let ncToPrint = this.$refs.ncPrint.innerHTML, pdfWidth = doc.internal.pageSize.width - 20, sanitizedContent;

        window.html2canvas = html2canvas;
        sanitizedContent = DOMPurify.sanitize(ncToPrint);

        doc.html(sanitizedContent, {
            callback: (doc) => {
                window.open(doc.output('bloburl'), '_blank').focus();
            },
            html2canvas: {
                width: pdfWidth,
            },
            margin: [0, 0, 10, 0],
            width: pdfWidth,
            windowWidth: pdfWidth,
            autoPaging: 'text',
            x: 10,
            y: 20,
        });`

Any help?