logologo
Guide
Practice
Configuration
Plugins
Showcase
Blog
Ecosystem
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
Guide
Practice
Configuration
Plugins
Showcase
Blog
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
logologo

Getting Started

Introduction
Setting Up the Environment
Quick Start Guide
Feature Navigation
Glossary of Terms
npm Packages

basic

Runtime

Runtime Access
Runtime API
Runtime Hooks
Rsbuild Plugin
Rspack Plugin
Webpack Plugin
Rspress Plugin
Vite Plugin
Metro
Type Hinting
Command Line Tool
Style Isolation

Data Solution

Data Fetching
Data Caching
Prefetch

Frameworks

Modern.js
Next.js

Deployment

Deploy with Zephyr Cloud

Debug

Enable debug mode
Chrome DevTools
Global variables

Troubleshooting

Overview

Runtime

RUNTIME-001
RUNTIME-002
RUNTIME-003
RUNTIME-004
RUNTIME-005
RUNTIME-006
RUNTIME-007
RUNTIME-008
RUNTIME-009

Build

BUILD-001
BUILD-002

Type

Overview
TYPE-001
Other
Edit this page on GitHub
Previous PageMetro
Next PageCommand Line Tool

#Type Hinting

Just like an NPM Package, Module Federation artifacts also generate types and enjoy hot-reloading of types, even though the artifacts are hosted on a remote CDN.

@module-federation/enhanced has type hinting enabled by default. This article will introduce several common usage scenarios and their specific configurations.

#Usage Scenarios

#Generating Types

When building with the build plugin provided by @module-federation/enhanced, type files are automatically generated.

#Loading Types

  1. Consumer modifies tsconfig.json

Add paths in tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "*": ["./@mf-types/*"]
    }
  }
}
  1. Start the consumer and producer

info: You don't need to worry about the startup order of the producer and consumer.

After starting, the consumer will automatically fetch the producer's type files.

#Type Hot Reloading

After modifying the producer's code, the consumer will automatically fetch the producer's types.

hot-types-reload-static

#Runtime API Type Hinting

INFO

If the builder is webpack, you also need to add **/@mf-types/** to watchOptions.ignored to avoid circular compilation issues caused by type updates.

You need to add ./@mf-types/* to the include field to enjoy Runtime loadRemote type hinting and type hot reloading.

tsconfig.json
{
  "include": ["./@mf-types/*"]
}

hot-types-reload

#Third-Party Package Type Extraction

Module Federation automatically extracts third-party package types to ensure that exposes file types can be accessed normally.

third-party

#Nested Type Re-export

Module Federation supports nested remotes and will automatically extract the types of nested remotes.

nested-remote

#Dynamic Type Hinting

Module Federation supports loading dynamic types and also supports hot updates.

dynamic-remote-hot-types-reload

#Configuration

  • dts: Type generation/loading
  • dev: Type hot reloading

#FAQ

#Project has circular compilation and cannot be terminated

A: It is likely that the compiler is watching for changes in the type folder or the dist directory. Add @mf-types to the ignored files.

For example, with webpack/rspack:

config.watchOptions = {
  ignored: ['**/node_modules/**', '**/@mf-types/**'],
};

#2. No type files are generated, how to find the reason?

Solution

  1. Add the FEDERATION_DEBUG=true environment variable before the project startup command.
  2. Set dts.displayErrorInTerminal to true.
  3. Start the project and check the console output.
  4. (Optional) If there is no error in the console, check the .mf/typesGenerate.log log file.