npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@module-federation/typescript

v3.1.6

Published

Webpack plugin to stream typescript for module federation apps/components

Readme

Federated Types

This plugin enables Typescript Types support for Module Federated Components.

Installation

$ npm i @module-federation/typescript

Usage

Register the plugin in webpack configuration (webpack.config.js) file

import webpack from 'webpack';
const { FederatedTypesPlugin } = require('@module-federation/typescript');

const federationConfig = {
  name: 'my-app',
  filename: 'remoteEntry.js',
  exposes: {
    //...exposed components
    './Button': './src/Button',
    './Input': './src/Input',
  },
  remotes: {
    app2: 'app2@http://localhost:3002/remoteEntry.js', // or Just the URL 'http://localhost:3002'
  },
  shared: ['react', 'react-dom'],
};

module.exports = {
  /* ... */
  plugins: [
    // ...
    new FederatedTypesPlugin({
      federationConfig,
      // ...
    }),
  ],
};

If you are running multiple remotes that use bi-directional module sharing, you may run into race conditions while starting up the webpack-dev-servers. The library now supports configuring retry options (which are enabled by default), along with the ability to serve the types out of the webpack compiler in a separate HTTP host.

Remember to only use typeServeOptions if you need to host them outside of webpack-dev-server locally, you'll also need to set the federationConfig for this plugin to reflect that new http server url.

module.exports = {
  /* ... */
  plugins: [
    // ...
    new FederatedTypesPlugin({
      federationConfig,
      typeFetchOptions: {
        /** The maximum time to wait for downloading remote types in milliseconds.
         * @default 2000  */
        downloadRemoteTypesTimeout?: number;
        /** The maximum number of retry attempts.
         * @default 3  */
        maxRetryAttempts?: number;
        /** The default number of milliseconds between retries.
         * @default 1000  */
        retryDelay?: number;
        /** Should retry if no types are found in destination. This could be due to another instance still compiling.
         * @default true  */
        shouldRetryOnTypesNotFound?: boolean;
        /** Should retry type fetching operations.
         * @default true  */
        shouldRetry?: boolean;
      },
      // Only enable if you need to serve types outside of webpack-dev-server
      typeServeOptions: {
        /** The port to serve type files on, this is separate from the webpack dev server port. */
        port?: number;
        /** The host to serve type files on. Example: 'localhost' */
        host?: string;
      }
      // ...
    }),
  ],
};

To enable verbose logging add folowing in webpack config:

infrastructureLogging: {
  level: 'log';
}

The Module Federation plugin is required to be registered separately from this plugin. The federation configuration provided to the Typescript plugin or Module Federation plugin can be different, as an example - to discern pure javascript remotes from Typescript remotes.

You need to register this plugin in both remote and host apps. The plugin will automatically create a directory named @mf-types in the host app - that contains all the types exported by the remote apps.

To have the type definitions automatically found for imports, add paths in tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "*": ["./@mf-types/*"]
    }
  }
}

baseUrl must also be set for paths to work properly

Plugin Options

| Setting | Type | Required | Default | Description | | ----------------------------- | ---------------- | -------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | additionalFilesToCompile | string[] | No | [] | Any additional files to be included (besides ModuleFederationPluginOptions.remotes) in the emission of Typescript types. This is useful for global.d.ts files not directly referenced. | | compiler | tsc or vue-tsc | No | tsc | The compiler to use to emit declaration files. Use vue-tsc to emit declarations from your Vue Templates | | disableTypeCompilation | boolean | No | false | Disable compiling types for exposed components | | disableDownloadingRemoteTypes | boolean | No | false | Disable downloading types from remote apps | | downloadRemoteTypesTimeout | number | No | 2000 | The maximum time to wait for downloading remote types. This is to prevent blocking compilation or hanging the plugin. | | federationConfig | | Yes | - | Configuration for ModuleFederationPlugin | | typescriptFolderName | string | No | @mf-types | The folder name to download remote types and output compiled types | | typescriptCompiledFolderName | string | No | _types | The folder name to output the raw output from the ts compiler |

Usage in Next.js

You need to manually pass the federationConfig object to the plugin. The remotes value should contain absolute path.

Sample code:

// next.config.js
const FederatedTypesPlugin = require('@module-federation/typescript');

module.exports = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    config.plugins.push(
      new FederatedTypesPlugin({
        federationConfig: {
          ...federationConfig,
          remotes: { app2: 'app2@http://localhost:3000/remoteEntry.js' },
        },
        // ...
      }),
    );
    return config;
  },
};

Support

Drop me a message on twitter for support/feedback, or maybe just say Hi at @prasannamestha

Credits

Shoutout to @ScriptedAlchemy for helping with the development of this plugin.