-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Build fails when Web Worker dynamically imports module also dynamically imported by the main thread #10057
Comments
For a workaround, add a module that re-exports everything from // logger2.ts
export * from './logger' // worker.ts
onmessage = e => {
import("./logger2").then(({ log }: any) => log(`worker: ${e.data}`)) // use logger2
}
export {} |
Thanks @sapphi-red, this looks like a nice workaround for direct imports. Unfortunately I ran into this while porting a project from Webpack to Vite and there are multiple dynamic imports brought in indirectly several levels deep. I'm not sure how feasible it will be to fork the entire call chain. Update: I was able to get it to work with the workaround. Thanks! |
Also struggling with this. In my case I'm not sure how to apply the workaround. My worker is a tiny wrapper around a class.
Inside @esturcke It sounds similar to your case. Could you shed any light on your approach? |
Interestingly, when using worker that requires the vite react plugin both the main app & the worker i don't get any of these errors and just see that all the dependencies have been bundled twice. Once for the use inside the worker and once in the main thread. Even though this works, it increases the bundle size considerably in my case because both react and a large lib i.e. |
…tejs#10057) This isn't perfect though, if the user wants to override the output names using `worker.rollupOptions.output`, he doesn't have access to the `workerName` as we have, as it's not a real Rollup placeholder
Describe the bug
I have created a Web Worker with
type: module
that dynamically imports a module shared with the main thread. In dev mode this works as expected, but when building I get (full logs below)Reproduction
System Info
Used Package Manager
yarn
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: