Skip to content
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

worker support #1320

Closed
12 tasks done
hardfist opened this issue Dec 1, 2022 · 22 comments
Closed
12 tasks done

worker support #1320

hardfist opened this issue Dec 1, 2022 · 22 comments
Assignees
Labels
team The issue/pr is created by the member of Rspack. tracking issue Category: A tracking issue for an RFC or an unstable feature.

Comments

@hardfist
Copy link
Contributor

hardfist commented Dec 1, 2022

Worker

Preview Give feedback
  1. feat pending triage team
    ahabhgk
  2. team
  3. p1-important team
  4. bug pending triage team
  5. release: bug fix team
  6. release: bug fix team
  7. release: bug fix team
  8. release: bug fix team
  9. stale team
  10. feat team
  11. team
    ahabhgk
@thecodrr
Copy link

worker-loader is required for basically any kind of Web Workers support so I think this should be high on the priority list.

@beaucollins
Copy link

beaucollins commented Mar 13, 2023

webpack says not to use worker-loader any more https://webpack.js.org/guides/web-workers/#syntax

We use the method describe in those docs but that is also broken with rspack.

@ahabhgk
Copy link
Contributor

ahabhgk commented Mar 14, 2023

Rspack currently not support web-worker or worker-loader, but we will work on supporting them later.

@thecodrr
Copy link

@beaucollins that method doesn't work on Firefox because there's no ESM support for Web Workers yet. Bundling is the only reliable way to make web workers work across browsers.

@beaucollins
Copy link

beaucollins commented Mar 14, 2023

@thecodrr webpack replaces the import.meta.url with a static string. Firefox handles it just fine. esm isn't involved in the bundled code.

@hardfist hardfist added this to the backlog milestone Mar 22, 2023
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Mar 22, 2023
@beaucollins
Copy link

Looks like #2340 will solve this for us. I'll report back.

@towavephone
Copy link

Look like #2340 can't resolve the web worker as the same with webpack 5:
Uncaught SyntaxError: Cannot use import statement outside a module
there always exists some extra file need to be imported except set the worker.js to type: module?

@beaucollins
Copy link

I can confirm that we can successfully use our worker code using rspack and the new URL('Module.ts', import.meta.url) syntax.

And yes, @thecodrr this also works in Firefox since the bundle output does not actually use ESM.

@birtles
Copy link

birtles commented Apr 18, 2023

I can confirm that we can successfully use our worker code using rspack and the new URL('Module.ts', import.meta.url) syntax.

I'm not sure what I'm doing differently.

With the following code using rspack 0.1.7, I get the TS file simply copied, untransformed (but renamed), to the output directory:

const dbWorker = new Worker(
  /* webpackChunkName: 'db-worker' */
  new URL('../db-worker/db-worker.ts', import.meta.url)
);

@beaucollins
Copy link

@birtles it seems I spoke too soon. The builds work but the Worker based feature is not.

@felixmosh
Copy link

I've the same issue as @birtles has, I would expect that a new entry will be added (with the path of the worker file path) dynamically with a worker target, so if the worker file path has imports it will be bundled together as it works in Webpack.

@underfin underfin changed the title worker-loader support worker support Apr 25, 2023
@underfin underfin assigned hardfist and unassigned ahabhgk Apr 25, 2023
@hyf0 hyf0 added the tracking issue Category: A tracking issue for an RFC or an unstable feature. label May 5, 2023
@h-a-n-a h-a-n-a modified the milestones: Planned, 0.1.12 - Patch May 16, 2023
@pushkargupta9807
Copy link

a gentle follow-up, do we have an approx ETA for this fix?

@jerrykingxyz jerrykingxyz modified the milestones: 0.1.12 - Patch, 0.1.13 - Patch May 23, 2023
@pushkargupta9807
Copy link

Do we have a patch/ experimental branch for this fix I can try ?

@hardfist
Copy link
Contributor Author

hardfist commented Jun 2, 2023

Do we have a patch/ experimental branch for this fix I can try ?

it is not supported now, we will support it soon

@hyf0 hyf0 removed this from the 0.1.13 - Patch milestone Jun 7, 2023
@ahabhgk ahabhgk added this to the Iteration Plan milestone Jun 7, 2023
@ahabhgk ahabhgk self-assigned this Jun 13, 2023
@ssddi456
Copy link

so if there is a milestone? this is a important feature for many complex system

@ahabhgk
Copy link
Contributor

ahabhgk commented Jun 26, 2023

I'm working on it, will support it in the next one or two weeks

@felixmosh
Copy link

felixmosh commented Jul 4, 2023

@ahabhgk I've tested v0.2.5 with the worker, looks like it splits the worker script into a separate file, but it is not bundling it's imports inside this bundle.

// some code
highlightWorker = new Worker(
        new URL('./worker.ts', import.meta.url)
);
// worker.ts
import config from './config'; // this file is not bundled inside the chunk that was created for worker.ts

console.log(config)

@ahabhgk
Copy link
Contributor

ahabhgk commented Jul 4, 2023

@felixmosh Is there any runtime error? Could you provide a reproduction so I can dig into this

@felixmosh
Copy link

felixmosh commented Jul 5, 2023

@ahabhgk this is weird, with the rspack starter, it works properly.

On my project, it throws,
image

You can try this branch: https://github.com/felixmosh/bull-board/tree/ui-with-rspack

yarn install
yarn start:dev

make sure you have radis running on a default port (via Docker or other)

@zackarychapple
Copy link
Contributor

Love seeing worker support landing.

@ahabhgk
Copy link
Contributor

ahabhgk commented Jul 6, 2023

@felixmosh Could you try 0.2.5-canary-7886e38-20230706011015, I believe it have been fixed by #3703

@ahabhgk
Copy link
Contributor

ahabhgk commented Jul 11, 2023

We have completed the basic support for web worker in v0.2.6, enough to cover most common cases, you can checkout our document for more detail

But there are some uncommon cases we still not able to cover for now:

Since these issue are blocked by the implementation of compile time evaluation and parser hooks in Rspack, so I decide to close this one and tracking these in their own issue, if you have any problem when using worker with Rspack, feel free to open a new issue and ping me.

@ahabhgk ahabhgk closed this as completed Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack. tracking issue Category: A tracking issue for an RFC or an unstable feature.
Projects
None yet
Development

No branches or pull requests