-1

I am creating a Chrome Extension. In the popup.js, I want to add a third party javascript library. (For reference let's say "uuid").

My end goal is to import a internal library, (and not uuid). I have used uuid for simplicity, my use case is much more complex. Manifest version is 3, and I don't want this behaviour through content script or background script. I only need it for chrome page's popup.html javascript file popup.js.

When I am using the syntax import { v4 as uuidv4 } from "uuid"; I get an error saying Uncaught TypeError: Failed to resolve module specifier "uuid". Relative references must start with either "/", "./", or "../".

If I import it by using

import { v4 as uuidv4 } from "../node_modules/uuid"; I get the error saying Failed to load resource: net::ERR_FILE_NOT_FOUND

saransh
  • 29
  • 6
  • Create an [MCVE](https://stackoverflow.com/help/minimal-reproducible-example) – Thomas Mueller Dec 15 '22 at 13:37
  • You need to build your code using webpack or a similar bundler to use NPM packages by their name because this is not compatible with JS modules specification. – wOxxOm Dec 15 '22 at 13:39

1 Answers1

-1

I could be wrong but last (and only one) time when I created chrome plugin I been foreced to download jquery library as file and have it inside my package. So I was unable to just "import" it, but I don't remember if that is limitation or there is some other way of importing library. So try to download optimized and minimized library and put it inside your package directory.

maximelian1986
  • 2,308
  • 1
  • 18
  • 32