2

I am trying to import websocket-async to use for my extension, but I get the error Cannot use import statement outside a module. From what I've read you can't simply import other scripts into the main file, some used dynamic import() here but for V3 I can't managed to make it work. I've created a separate js file and added it to the:

"web_accessible_resources": [
    {
        "matches": ["<all_urls>"],
        "resources": ["src/imports.js"]
    }
],

But it still throws the error. And even if I could make it work, how could I send my Websocket object to the main thread if it didn't let me import it in the first place?

Edit: Here is how main.js is loaded:

"content_scripts": [
    {
        "matches": ["https://*.docs.google.com/*"],
        "js": [
            "src/main.js",
            "src/audio-worker.js",
            "src/dist/websocket-async.esm.js",
            "src/dist/websocket-async.umd.js"
        ],
        "css": ["src/style.css"],
        "type": "module"
    }
],

also in package.json it has the type module

VladTbk321
  • 73
  • 8
  • 1
    The main script where you do import should be loaded as a module. How is this script currently declared/loaded? – wOxxOm Mar 17 '23 at 15:37

0 Answers0