Skip to content

[Bug]: lazyBarrel can emit bare forwardRef(...) from a React component imported through a barrel, causing forwardRef is not defined at runtime #8799

@wojtekmaj

Description

@wojtekmaj

Reproduction link or steps

rolldown-lazy-barrel-bug 2.zip

Reproduction steps:

npm install
npm run reproduce

The 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:

  1. build.rolldownOptions.experimental.lazyBarrel = true enabled.
  2. Importing a React component through a package barrel entry.
  3. Barrel pattern that has both named and default exports in the same barrel:
    import AsyncButton from './AsyncButton.js';
    
    export { AsyncButton };
    export default AsyncButton;
    If the barrel has only a default export, or only a named export, the bug stops reproducing.
  4. 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.3

Any 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

No labels
No labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions