How to get a class or class instance in a WebWorker

I have this class which I would like to use in multiple places. This class is in its own js-file and looks like this

export class MyCls {
    function doIt(a, b) { ... }

To be able to use this class I have to load my app-code as a ES-module

<script scr="/main.js" type="module"></script>

Now I can use Dynamic Imports and load the above class as follows

const Clz = await = import('/clz.js');

So far, no problems!

However, I'm also working with Web Workers. And yes, I would like to use this class inside the web worker. To do that, I see 4 possible solutions:

  1. use Dynamic imports inside the Web Worker
  2. use importScripts to load the file
  3. Pass the class via postMessage to the worker.
  4. Stringify the class and pass it to the worker with postMessage

All four sound pretty valid to me, but none of them actually them work

  1. Dynamic imports are not supported inside Web Workers
  2. importScripts doesn't understand the export keyword
  3. A class cannot be passed to the worker, it gives an error:
Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Worker': class o{constructor()
  1. It is not possible to stringify a class :(

I cannot believe that this is not possible, so any suggestions are very welcome!!?

UPDATE: Just found this

It is suggested that you can load ES modules with WebWorker

new Worker("worker.js", { type: "module" });

Interesting (not tested it yet)