0

I am making a browser extension that gets the code of a div and converts it into html. I have tried doing this with jspdf , html2pdf, but none of that worked perfectly.

So i used html-to-pdfmake but i cannot import it in my popup.js

var pdfMake = require("pdfmake/build/pdfmake");
var pdfFonts = require("pdfmake/build/vfs_fonts");
pdfMake.vfs = pdfFonts.pdfMake.vfs;
var htmlToPdfmake = require("html-to-pdfmake");
  • If imported like this it gives me the error
Uncaught ReferenceError: require is not defined

if imported using "import"

import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
pdfMake.vfs = pdfFonts.pdfMake.vfs;
import htmlToPdfmake from "html-to-pdfmake";

it gives me

Uncaught TypeError: Failed to resolve module specifier "pdfmake/build/pdfmake". Relative references must start with either "/", "./", or "../".

Any ideas how to import it . The package doesn't have any tutorials as it is unpopular.

I have tried

import htmlToPdfmake from "./node_modules/html-to-pdfmake";

but that doesn't work as well.

Ds Adithya
  • 43
  • 6
  • 1
    Does this answer your question? [importing a package in ES6: "Failed to resolve module specifier "vue""](https://stackoverflow.com/questions/52612446/importing-a-package-in-es6-failed-to-resolve-module-specifier-vue) – jabaa Apr 04 '23 at 13:15
  • 1
    Either use a bundler or configure your web server to serve `node_modules` and use the native module system or a module loader. There are dozens or hundreds of ways to use modules. Do some research, choose one way and try it. Then, ask a specific question. – jabaa Apr 04 '23 at 13:19
  • Load like script can help you? ` ` – TheNikCD Apr 04 '23 at 13:27
  • Either use webpack or add a file extension `.js` and use relative path for the native ES import to work. – wOxxOm Apr 04 '23 at 15:09

1 Answers1

-1

From where do you want load this modules?

Maybe this will help you How to import ES6 modules in content script for Chrome Extension

ABJ
  • 37
  • 1