i have the following code in worker.js and i am trying to import KMeans inside of it, and i export the worker as shown.
import KMeans from "tf-kmeans";
const splitText = () => {
...
const kmeans = new KMeans({});
...
};
};
let code = splitText.toString();
code = code.substring(code.indexOf("{") + 1, code.lastIndexOf("}"));
const blob = new Blob([code], { type: "application/javascript" });
const worker_script = URL.createObjectURL(blob);
export default worker_script;
In the main component where i want to call the worker, i call it using the following:
let worker = new Worker(new URL(worker_script, import.meta.url), {
type: "module",
});
but when i use the worker i get the following error:
Uncaught ReferenceError: tf_kmeans__WEBPACK_IMPORTED_MODULE_1___default is not defined
How can this be solved? TIA