Breaks on latest gatsby, only when there is a webpack cache
gersomvg opened this issue · 5 comments
It seems like after I start the Gatsby dev server a second time — and webpack has a cache — the worker doesn't load with the exported worker functions set on the object. The moment I clear webpack's cache and restart the dev server, the worker loads fine again.
Does this very limited description by any chance give you a quick insight about what might be causing this?
I'm afraid I can't really give more details, because the inner workings of gatsby/webpack is just one big black box to me.
I can of course make a minimal reproduction with a newly bootstrapped gatsby, if this would be of any help?
Bypassed this issue by using webpack / Workers directly without this loader and RPC implementation. Feel free to investigate further or close this issue if you don't plan to have support for Gatsby out of the box 👍🏻
Getting this as well.
Attached a debugger to investigate.
The problem is the loader is not hitting the parser anymore - because there's nothing to parse thanks to the cache; and thus the export declaration hook that is meant to collect exported methods is no longer run.
However, as the output of the loader is marked non-cachable, that part actually will rebuild every time. And ofcourse, after the first build it gets an empty array of collected methods.
The solution here is, I think, to use the Webpack cache to cache the array of exported methods along with the modules. or to somehow mark the entry module of the worker as non-cacheable which forces it to always be processed from source, and always have the parser run.
[EDIT]
Actually: it's even easier than that.
There is no reason to manually bookkeep the exports with the parser hook at all.
Technically, under the assumption that users will only export methods from the entry module of the worker, the only thing you need is:
const exportNames = compilation.moduleGraph.getProvidedExports(entryModule);
Running into the same issue with a recent version of create react app (v. 5.0.1). Had to disable the webpack cache as a workaround. Would be great if this could be taken care of on the library side
yes same situation, when I cancel 的 webpack cache, it works fine. So how to make them coexist