Description
🐞 Bug report
Command (mark with an x
)
- new
- build
- serve
- test
- e2e
- generate
- add
- update
- lint
- extract-i18n
- run
- config
- help
- version
- doc
Is this a regression?
Yes, worked in v11
Description
Application with a web worker requires 2 TS compilations, one for the app itself and one for the worker.
This is supported by angular via the webWorkerTsConfig
build target configuration.
We exclude the web worker file from the client build and include it in the webWorkerTsConfig
file.
This works fine since the IVY loader will try compiling it with both programs, the first emit wins.
With SSR server compilation this is not the case, we don't have a worker compilation, instead we need to handle the case
where there is no worker available in the environment and provide an alternative.
In V11 this worked fine, since we used webpack 4 and worker-loader
. In server builds we just
don't include the worker-loader
which means it will not detect the worker TS file module and will not
try to compile it.
Now, with the new Webpack 5 native worker support we no longer use worker-loader
.
new Worker(new URL('../search.worker', import.meta.url), { name: 'searchWorker', type: 'module' });
Webpack will natively detect the search.worker.ts
module and add it to the compilation, passing it to the IVY loader
which now has only 1 TS program configuration, which exclude the worker files so it will fail saying that the TS file is not part of the compiler configuration and we should add it to "include" or "files".
As a workaround, I managed to bypass this issue with file replacements and in server builds I just replace the file referencing the worker (new URL('...')
) with a noop file that does not reference it.
This is good for some scenarios but other might not fit this.
I guess one can also go back to the worker-loader
method and change the new URL
syntax to a literal string.
🌍 Your Environment
@angular-devkit/architect 0.1200.0
@angular-devkit/build-angular 12.0.0
@angular-devkit/core 12.0.0
@angular-devkit/schematics 12.0.0
@angular/flex-layout 12.0.0-beta.34
@nguniversal/common 12.0.0
@nguniversal/express-engine 12.0.0
@schematics/angular 12.0.1
ng-packagr 12.0.0
rxjs 6.6.3
typescript 4.2.4
Anything else relevant?