I am using jsPDF and have. installed it using npm and I'm importing to my javascript file however I get this error
Uncaught SyntaxError: Cannot use import statement outside a module
I have tried adding module type to package.json however didn't change anything. What am I doing wrong?
UPDATE: adding type="module" to the CDN did not fix the issue either
app.js:
import {jsPDF} from "jspdf";
const pathsInstance = new Paths();
// Progressive app
if (debug === false) {
window.onload = () => {
'use strict';
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('./pwa.js').then(reg => {
// Trigger this after timeout
reg.update();
});
}
}
}// Event handle on page load.
window.addEventListener('load', () => {
....
pckage.json:
{
"name": "board",
"version": "1.1.0",
"description": "Simple, standalone, flexible and very lightweight board app/PWA in JavaScript.",
"main": "config.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lablnet/board.git"
},
"author": "Muhammad Umer Farooq",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/lablnet/board/issues"
},
"homepage": "https://github.com/lablnet/board#readme",
"dependencies": {
"connect": "^3.7.0",
"jspdf": "^2.4.0",
"serve-static": "^1.14.1"
}
}