Skip to content

Node SDK does not properly handle dynamic imports when processing ESM remoteEntry #4216

@RandomlyChristen

Description

@RandomlyChristen

My remoteEntry is built using:

"vite": "6.4.1"
"@module-federation/vite": "1.9.0"
However, the remoteEntry itself should not cause concern. It is a proper MF Remote in ESM format without circular dependencies, including get and init, and it exports a React component for SSR.

The consumer of this remote is a React server-side renderer running in the Node runtime, using:

"vite": "6.4.1"
"@module-federation/enhanced": "0.21.3"
Although Vite is primarily a browser runtime-oriented application builder, it also supports SSR runtimes, so this should not be an issue.

The application consistently throws the error ReferenceError: default is not defined immediately after the remote’s dynamic import statement.

Debugger evaluation shows that await import() resolves as a Module, but accessing attributes on it is not available.

Image

This module is handled inside the importModuleDynamically callback of vm.SourceTextModule from module-federation/core/sdk/node.
I will share a PR addressing this.

Image

PR) #4217

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