-
Notifications
You must be signed in to change notification settings - Fork 737
[Bug]: lazyBarrel can emit bare forwardRef(...) from a React component imported through a barrel, causing forwardRef is not defined at runtime #8799
Description
Reproduction link or steps
rolldown-lazy-barrel-bug 2.zip
Reproduction steps:
npm install
npm run reproduceThe repro script builds, starts preview, opens the page in Playwright, and verifies the runtime error automatically.
Disclaimer: 🤖 This reproduction was AI-generated, but every line was reviewed by a human and reproduction was manually tested.
What is expected?
Build succeeds, preview starts, and the page renders without crashing.
The bundle should not reference React APIs as bare identifiers (e.g. forwardRef), so there is no runtime failure.
What is actually happening?
Production build succeeds and preview starts, but the page crashes at runtime with:
forwardRef is not defined
The emitted bundle contains code shaped like:
u = forwardRef(function (e, t) { ... })In the broken output, forwardRef is emitted as a bare identifier instead of being referenced via a bound React import/namespace.
Minimal trigger conditions observed:
- build.rolldownOptions.experimental.lazyBarrel = true enabled.
- Importing a React component through a package barrel entry.
- Barrel pattern that has both named and default exports in the same barrel:
If the barrel has only a default export, or only a named export, the bug stops reproducing.
import AsyncButton from './AsyncButton.js'; export { AsyncButton }; export default AsyncButton;
- sideEffects: false in the package package.json appears to matter (as lazyBarrel does not apply in such case).
System Info
System:
OS: macOS 26.3
CPU: (10) arm64 Apple M1 Max
Memory: 149.84 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.11.1 - /usr/local/bin/node
Yarn: 1.22.22 - /Users/wojciech.maj/.yarn/switch/bin/yarn
npm: 11.6.2 - /usr/local/bin/npm
pnpm: 10.30.1 - /usr/local/bin/pnpm
Browsers:
Chrome: 146.0.7680.80
Firefox: 141.0.3
Safari: 26.3Any additional comments?
If the app is changed to import the concrete file directly instead of the barrel, for example:
import AsyncButton from 'react-async-button-bug/dist/AsyncButton.js';the runtime error goes away. This suggests the issue is tied to the lazyBarrel optimization path for this barrel pattern rather than to the component module itself that imports forwardRef.
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackPriority
Effort