How to import a typescript module inside a Web Worker in angular 8?

后端 未结 1 321
感情败类
感情败类 2021-01-21 04:53

Since Angular 8, you can now generate web worker to your app from the CLI. I did so exactly like the official guide:

https://angular.io/guide/web-worker

And it w

相关标签:
1条回答
  • 2021-01-21 05:37

    My problem was that this shared module I was trying to import was created with ng generate module. In doing so, angular automatically imports NgModule, CommonModule and adds an @NgModule with declarations and imports to the exported class. These give you access to the DOM, and web workers cannot have access to the DOM. Which is what the compile error I was getting was talking about. Even tho I wasn't really using these imports and none of these were the reason why I was importing this module into the webworker. They were there anyway and they were causing the error.

    I fixed it by simply removing the 2 import statements for NgModule, CommonModule and the whole @NgModule from my shared module. Then it imported fine without any errors into the web worker.

    0 讨论(0)
提交回复
热议问题