Circular dependency not working with worker-loader?
I've got package A that depends on package B, which depends on package C (worker), which depends on package A.
I'm getting an error like this: http://trusktr.io:7777/ixujinuzij
This issue was moved from webpack/webpack#1564 by @evilebottnawi. Original issue was by @trusktr.
I agree, I had a similar issue. For me, the build was never completed and just hung. I worked around it by removing circular dependencies in my code.
I have also run into this issue recently. In my case, I am trying to write 2 versions of a library (one has the main thread run expensive() directly, and the other has main posting runExpensive messages to a web worker).
I only managed to get around this by writing 2 separate files main.js (expensive() runs in-place) and worker.js (runExpensive message is posted to a webworker), and then using the nasty webpack.NormalModuleReplacementPlugin in my webpack config.
Instead of importing the module directly, my code was changed to something like import * as api from ./api/THREAD_TARGET and then...
new webpack.NormalModuleReplacementPlugin(/THREAD_TARGET/, function(resource) {
// Imports occuring in a webworker should use main; otherwise worker.
const compiler = resource.contextInfo.compiler;
const mainOk = (compiler && compiler.startsWith("worker-loader"));
if (mainOk) {
const newRequest = resource.request.replace(/THREAD_TARGET/, "main");
resource.request = newRequest;
} else {
const newRequest = resource.request.replace(/THREAD_TARGET/, "worker");
resource.request = newRequest;
}
})
@rcrowell What is version of webpack?