typescriptweb-workerangular2-aotangular10

Angular 10 Web worker not working in production but works in developmnet


I have an Angular10 web application where I load OpenCV on a web worker. I added the web worker according to the documentation here https://angular.io/guide/web-worker and everything works fine in development but not in production.

Here is the code from the web worker file https://github.com/Usergitbit/EchelonExtractor/blob/master/src/app/services/open-cv.worker.ts

Using some console logging I noticed that in production I never get a response from sending a message to the worker so I checked the compiled file and it looked like most of my code was missing because there were none of the path strings present.

Then I disabled AOT and rebuilt for production and my code was now present and things seemed to work fine. What is the cause of this? I suspect it might be happening because of the interfaces I'm importing into the worker file resulting in problems during the AOT build. Perhaps there is some kind of configuration I need to do in order to make it work?


Solution

  • Upgrading to Angular11 seems to have solved the issue.