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]: Incorrect conditional imports are generated when usedExports is enabled #8649

Open
JohnDaly opened this issue Dec 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@JohnDaly
Copy link

JohnDaly commented Dec 9, 2024

System Info

System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Max
Memory: 11.60 GB / 64.00 GB
Shell: 5.9 - /bin/zsh

Binaries:
Node: 20.5.0
Yarn: 1.22.21
npm: 9.8.0
pnpm: 9.4.0

Browsers:
Chrome: 131.0.6778.109
Safari: 17.6

npmPackages:
@rspack/cli: ^1.1.5 => 1.1.5
@rspack/core: ^1.1.5 => 1.1.5

Details

When using usedExports: true with multiple entrypoints it's possible for the generated conditional imports to be incorrect, causing the application to crash.

In my example, I have a Webpack / rspack application that has multiple entrypoints. Each entrypoint is its own React application, and the root entrypoint is responsible for selecting which one to load at runtime.

Cache groups are configured, so that chunks can be shared between the applications. When using rspack, I've encounter a problem where the bundler is incorrectly identifying an export as being used only by "Application A", but in reality it should be used by both "Application A" and "Application B"

When bundling with Webpack, the code runs both applications without crashing, so I believe this is a bug in rspack.

Reproduce link

https://github.com/JohnDaly/rspack-used-exports-repro

Reproduce Steps

  1. Run pnpm run build
  2. Serve the rspack output with npx serve ./rspack-dist
  3. View the application in the browser
  4. Look in the console and note the Uncaught TypeError: Cannot read properties of undefined (reading 'X') error

In the rspack output, we see that "Application A" has a runtime ID of "705" and "Application B" has a runtime ID of "525".

We can also see that the Subscription variable is only initialized for runtime "705" (Application A):
https://github.com/JohnDaly/rspack-used-exports-repro/blob/d6b06696de558b67b2c2e7428d650b45e8d93c7d/rspack-dist/redux.js#L413-L416

When trying to run "Application B", the application will crash because it needs access to the Subscription variable, but it is not present.

@JohnDaly JohnDaly added bug Something isn't working pending triage The issue/PR is currently untouched. labels Dec 9, 2024
@inottn inottn removed the pending triage The issue/PR is currently untouched. label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants