0

I am trying to import a library in JS but it won't work.

I am getting this error message : Uncaught TypeError: Failed to resolve module specifier "html-to-image". Relative references must start with either "/", "./", or "../".

Here is my code in my js file:

import * as htmlToImage from "html-to-image";
import { toPng, toJpeg, toBlob, toPixelData, toSvg } from "html-to-image";

and here is ho i import my js file in html :

        <script type="module" src="./packOpener.js"></script>

I also installed esbuild (npm install esbuild ) since it could apparently help but whithout success...

Any idea ? :)

I am quite new and i have been block all day on this problem.

  • You have to use a bundler to import node modules in the browser. `esbuild` is fine, you you have to use it, not just install. I would recommend `vite` https://vitejs.dev/guide/ – Konrad Oct 11 '22 at 22:02
  • Thanks for your answer but I can't find ny documentation on ho to use either vite or esbuild to makes import works :( – Aymeric Sandoz Oct 11 '22 at 22:27
  • It's easier to start from scratch `npm create vite@latest` – Konrad Oct 11 '22 at 22:33

0 Answers0