Skip to content

[Bug]: react and react-dom as shared dependencies crash in Safari #408

@crijke

Description

@crijke

Describe the bug

When sharing react and react-dom dependencies in module federation with module-federation-vite, the shared dependencies fail to load in Safari and are causing the app to crash with errors like these, with the react dependency being undefined when it is accessed:

  • Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'f$1.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED')
  • ReferenceError: Cannot access 'default' before initialization.
    (anonymous function) — virtualExposes-Di8U-Ssu.js:8

Tested with
react / react-dom: 18.3.0 / 18.3.1
Safari: 26.2 on macOS

The issue can't be reproduced with rspack so it seems to be specific to module-federation-vite.

We found that adding vite-plugin-top-level-await (https://www.npmjs.com/package/vite-plugin-top-level-await) fixes the issue, so it seems to be related to async initialization of the shared dependencies.

I created a minimal repo to reproduce the issue
repo: https://github.com/crijke/module-federation-vite-example
branch: demo/safari-shared-dependencies-mfe-bridge

Version

6.2.1

Reproduction

https://github.com/crijke/module-federation-vite-example

Relevant log output

- Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'f$1.\_\_SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED')
- ReferenceError: Cannot access 'default' before initialization.
  (anonymous function) — virtualExposes-Di8U-Ssu.js:8

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions