OK, I think you messed with automatic bundlers like everybody these days...
Replace first lines with these:
(function (factory) {
if(typeof define === 'function' && define.amd)
define(factory)
else
window.jsPDF = factory();
}(function () { 'use strict';
...
Now we can make:
var x = new jsPDF();
without errors.
File I'm referred to: jspdf.debug.js at the dist folder of your project.
Now let's include minified version from CDN:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test jsPDF</title>
</head>
<body style="">
...
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>
</body>
</html>
browser prints at console:
Script error.
at: https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js
line: 0
The above happens when we dynamically append the <script> tag at the bottom of <body> (using custom code here).
Amazingly, no error prints out if we hard-code the <script> tag!
From stackoverflow one proposes:
const jsPDF = require('jspdf')
var pdf = new jsPDF('p', 'pt', 'letter')
but you have to check what is the result in terms of javascript code when we issue a require in the Node environment - I mean what's the code that the browser runs? (browser javascript is not Node javascript).
Now can you change the CDN version of the library?
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.
Currently working on that...
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.
Always use
const { jsPDF } = require("jspdf"); ---> define like this in nodejs if your file is .js extension
`const doc = new jsPDF('p');`
Then like this, it will work smoothly
Most helpful comment
Always use
const { jsPDF } = require("jspdf");---> define like this in nodejs if your file is .js extensionThen like this, it will work smoothly