Can you create a web worker on a vanilla javascript file? TypeError: worker.postMessage is not a function [closed]

  angular, javascript, ng-build, web-worker

I am trying to create a web worker outside of the DOM. that fetches some data before angular starts building.
That way we can use the time it takes for angular to build to fetch a large amount of data.
I am thinking of doing this on an ng build script. But I am having trouble getting a web worker initialized.

Here is my code:

const Worker  = require('worker-plugin');
const worker = new Worker('./build.worker.ts', { type: 'module' });
worker.onmessage = ({ data }) => {
    console.log('this is the message inside build');

but I keep getting the error:

TypeError: worker.postMessage is not a function

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.