// Dummy module for getting environment setup.
let EXPORTS = {
    hello() {
        return 'hello';
    }
}

// The technique below allows code to work both in-browser and in Node.
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
    module.exports = EXPORTS;
} else {
    //@ts-ignore
    window.worker = EXPORTS;
}
// Dummy module for getting environment setup.
class MyWorker {
    public hello() {
        return 'hello';
    }
}

// The technique below allows code to work both in-browser and in Node.
if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
    module.exports = new MyWorker();
} else {
    //@ts-ignore
    window.worker = new MyWorker();
}
--- 
+++ 
@@ -1,14 +1,14 @@
 // Dummy module for getting environment setup.
-class MyWorker {
-    public hello() {
+let EXPORTS = {
+    hello() {
         return 'hello';
     }
 }
 
 // The technique below allows code to work both in-browser and in Node.
-if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
-    module.exports = new MyWorker();
+if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
+    module.exports = EXPORTS;
 } else {
     //@ts-ignore
-    window.worker = new MyWorker();
+    window.worker = EXPORTS;
 }
Use an object instead of a new class instance.
