question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: c.autoTable is not a function

See original GitHub issue

hello,你好! it can works in vue3 dev env. but when i build it ,it can not works in product env. image

"jspdf": "^2.5.0",
"jspdf-autotable": "^3.5.23",
import jsPDF from "jspdf";
 import "jspdf-autotable";
 const print = async () => {
      const PageMargin = { top: 20, right: 10, bottom: 15, left: 10 };
      const doc = new jsPDF({
        orientation: "p",
        unit: "mm",
        format: "a4",
      });
await something .......
 doc.autoTable({
          styles: { font: "hansans-normal" },
          columnStyles: { europe: { halign: "center" } }, // European countries centered
          body: state.datasource,
          columns: state.pdfheader,
          startY: startY, //第一次
          margin: PageMargin,
        });
}

TypeError: c.autoTable is not a function

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
FPG-Alancommented, Feb 10, 2022

I had meet the same problem today, and I use Vite which use rollup-commonjs-plugin to convert commonjs module to ESM during build.

After looking into dist code, I found somehow commonjs plugin did not convert require("jspdf"):

...
module.exports = e(function() {
      try {
        return require("jspdf");
      } catch (t4) {
      }
    }());
...

which should be something like this:

var require$$0 = /* @__PURE__ */ getAugmentedNamespace(jspdf_es_min);
...
...
module.exports = e(function() {
      try {
        return require$$0;
      } catch (t4) {
      }
    }());

since autotabe need apply itself as plugin to jspdf, this is the immediate cause of the problem.

After further investigation, I found in Vite version 2.6.3, they upgrade commonjs plugin to version 21.0.0 upgrade to @rollup/plugin-commonjs 21.x and what happened in commonjs plugin to version 21.0.0?

they set ignoreTryCatch default as true use safe default value for ignoreTryCatch

and, this repo, use try catch when require jspdf

So, in conclusion, to solve this problem, explicitly set ignoreTryCatch to false:

defineConfig({
...
  build: {
    commonjsOptions: {
      ignoreTryCatch: false
    }
  }
  ...
})
1reaction
chun222commented, Jan 22, 2022

help me 55555555

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsPDF AutoTable - autoTable is not a function
I have jspdf and jspdf-autotable installed via npm, I confirmed they are in the node modules. I've imported both plugins this way: import...
Read more >
simonbengtsson/jsPDF-AutoTable - Gitter
Third time hit the generatePdf it genereate pdf properly,. Issue 2: Sometime its throws an error saying TypeError: doc.autoTable is not a function....
Read more >
autoTable is not a function error when using jspdf in ...
Hello All, I face issue with using jsPDF library in sap ui5. I have written the below code in my controller. var doc...
Read more >
jsPDF-AutoTable
I'm trying to create a table using jspdf autotable but i got an issue in html:"tableId" it is not printing all the loop...
Read more >
jspdf-autotable
Generate pdf tables with javascript (jsPDF plugin). Latest version: 3.5.28, last published: a month ago. Start using jspdf-autotable in your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found