developit/workerize-loader

The hot reload of CRA/Webpack is breaking the worker when using ES2015 children modules

nicolas-zozol opened this issue · 2 comments

Usng CRA, but also after ejecting the webpack config, I have this code calling the main webworker :

// App.js - React jsx file
import worker from 'workerize-loader!./worker/main.worker.js';// eslint-disable-line import/no-webpack-loader-syntax

function calculation() {
    const w = worker();
    return w.main(getConfig());
}

Then this worker is calling a ES2015 module:

// main.worker.js - entrypoint of the worker module
import {ascii_to_oct} from "./first";

export function main (config){
    return ascii_to_oct("long calculation value");
}

And in the child module, I just return a value

first.js
export function ascii_to_oct(str)
{
    return 42
}

I run yarn start and everything works, but if ever I update 42 to 43, I will have the message
TypeError: w.main is not a function

image

Then if I restart manually yarn start, it works again.

duplicate #24.

Yup, closing as duplicate of #24. Fixed on master, will release shortly.