-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with Worker & SSR (universal) #20877
Comments
Having a file in the a server compilation that depends on Browsers APIs seems wrong to me because Node.JS worker API is not fully interchangeable with that of the Browser, even how they are refereced where in the browser the The fact that the build previously succeeded seems like a problem, since that might have caused incorrect behaviour if you were dependent on the worker to render the page. I am also surprised to why this didn't previously crash the server during runtime with an error like |
Hi @alan-agius4, thanks for taking the time to explain. The reason there will not be a reference error is the safe guard checking. if (typeof Worker !== 'undefined') {
this.adapter = new WorkerSearchAdapter();
} else {
this.adapter = new WindowSearchAdapter();
} It seems, AFAIK, that there's no real solution here. The problem is in the module that holds new Worker(new URL('../search.worker', import.meta.url), { name: 'searchWorker', type: 'module' }); In older webpack, this was handled by I worked around this one using the fileReplacements feature through Since I do have safe runtime type protection I do need webpack to skip this one. The error is thrown because webpack will pass this file to the loaders while the file is EXCLUDED from the loaders. The CLI must be smart here and detect that this file was explicitly excluded in TS configuration so webpack should not really process it. It might be a bug in webpack, or how webpack detect TS files... I don't know these internal between CLI and webpack |
…ver builds Web-workers are not supported on the server and therefore we should not try include them in server builds. Closes #20877
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 Bug report
Command (mark with an
x
)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 justdon't include the
worker-loader
which means it will not detect the worker TS file module and will nottry to compile it.
Now, with the new Webpack 5 native worker support we no longer use
worker-loader
.Webpack will natively detect the
search.worker.ts
module and add it to the compilation, passing it to the IVY loaderwhich 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 thenew URL
syntax to a literal string.🌍 Your Environment
Anything else relevant?
The text was updated successfully, but these errors were encountered: