score:0

Accepted answer

I needed to add this line right above the first line of my worker function

/* eslint-disable-next-line no-restricted-globals */


let mytimer;
/* eslint-disable-next-line no-restricted-globals */
self.onmessage = function(evt) {
    clearInterval(mytimer);

      if(evt.data.message === 'pause' || evt.data.message === 'stop' || evt.data.message === 'skip'){
        postMessage(evt.data.time)
      }

    if (evt.data.message == "start" || evt.data.message == "break") {
        var i = evt.data.time;
        mytimer = setInterval(function() {
            i--;
            postMessage(i);
        }, 1000);
        
    } 
  
};

And also have this in my config-overrides.js

config.output.globalObject = 'this';
module.exports = function override(config, env) {
    config.module.rules.push({
        test: /\.worker\.js$/,
        use: { loader: 'worker-loader' },
        
      })
      config.output.globalObject = 'this';
    return config;
  }

Related Query

More Query from same tag