-
-
Notifications
You must be signed in to change notification settings - Fork 780
Description
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
- Run
pnpm run build - Serve the
rspackoutput withnpx serve ./rspack-dist - View the application in the browser
- 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.