Skip to content

Pure Runtime Host Fails to Initialize Share Scope, React Not Shared (Invalid Hook Call) #4071

@GururajChadaga

Description

@GururajChadaga

Describe the bug

The repository demonstrates a critical issue with pure runtime Module Federation:

Summary:
when using @module-federation/runtime on the host and plugin-built remoteEntries, the host's share scope is not initialized, leading to multiple React instances and hook errors. The same configuration works as expected when using the build plugin on the host, suggesting an issue in how the runtime API participates (or doesn't) in share scope initialization.

  1. The hostbuildtime application (using Module Federation at build time) shows correct initialization of webpack share scopes, and shared dependencies like React work as expected.
  2. The hostruntime application attempts to use createInstance from the Module Federation runtime to load remotes (app2, app3) at runtime, but the webpack share scope is empty. This causes React sharing to fail, resulting in an "invalid hook call" error when loading and rendering remote components.

I have tried providing shared dependencies directly under the shared option of createInstance, and also using mf.registerShared, but the problem persists. The share scope object (webpack_share_scopes) remains empty, and singletons like React are not correctly shared.

Brief Reproduction:

  1. Clone the repo and install dependencies: npm install
  2. Start all applications: npm run start
  3. Access the following apps in your browser:
Image Image

Reproduction

https://github.com/GururajChadaga/mf-dynamic-remotes-pure-runtime

Used Package Manager

npm

System Info

System:
    OS: macOS 15.6.1
    CPU: (10) arm64 Apple M4
    Memory: 272.31 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.17.0 - /usr/local/bin/node
    Yarn: 1.22.22 - ~/myorg/myorg/node_modules/.bin/yarn
    npm: 11.4.2 - /usr/local/bin/npm
    pnpm: 10.12.4 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 140.0.7339.133
    Safari: 18.6

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions