Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Circular dependency not working with worker-loader? #266

Open
webpack-bot opened this issue Jul 29, 2020 · 3 comments
Open

Circular dependency not working with worker-loader? #266

webpack-bot opened this issue Jul 29, 2020 · 3 comments

Comments

@webpack-bot
Copy link

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.

@mwanago
Copy link

mwanago commented Nov 25, 2020

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.

@rcrowell
Copy link

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;
        }
      })

@alexander-akait
Copy link
Member

@rcrowell What is version of webpack?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants