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

[Bug]: prod build marks worker export as not used #9451

Open
felixmosh opened this issue Feb 23, 2025 · 2 comments
Open

[Bug]: prod build marks worker export as not used #9451

felixmosh opened this issue Feb 23, 2025 · 2 comments

Comments

@felixmosh
Copy link

Version

System:
    OS: macOS 15.3.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 318.75 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 133.0.6943.127
    Safari: 18.3
  npmPackages:
    @rsbuild/core: ^1.2.8 => 1.2.11

Details

for some reason prod build marks the exported function as not used.

Reproduce link

https://github.com/felixmosh/rsbuild-worker-prod-bug

Reproduce Steps

  1. yarn install
  2. yarn dev - (check that all works, the worker prints worker content)
  3. yarn build
  4. node ./dist/server.js - fails since the exported variable is marked as unused (based on the comments)
@9aoy
Copy link
Contributor

9aoy commented Feb 25, 2025

Rspack enables optimization.usedExports in production mode by default, and did not detect that this export was used, so it was tree-shaked.

Rspack cannot statically analyze this syntax:

+ const worker = await eval('import(workerPath)');

  if(worker.default && typeof worker.default.default === 'function') {
    await worker.default.default();
  }

@felixmosh
Copy link
Author

felixmosh commented Feb 25, 2025

Hi @9aoy thank you for the reply...

I've change the eval to __non_webpack_require__, still the same output :| (you can check the change in the repo)

@9aoy 9aoy transferred this issue from web-infra-dev/rsbuild Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants