Estoy usando jsPDF y lo instalé usando npm y estoy importando a mi archivo javascript, sin embargo, aparece este error Uncaught SyntaxError: Cannot use import statement outside a module
Intenté agregar el tipo de módulo a package.json, sin embargo, no cambié nada. ¿Qué estoy haciendo mal?
ACTUALIZACIÓN: agregar type="module" a la CDN tampoco solucionó el problema
aplicación.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', () => { ....paquete.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" } }