Webpack Module Federation infinite reload

Discussão em 'Angular' iniciado por RattleStork.org, Julho 22, 2025.

  1. I try to split my angular 20 monolith and seperate my blogs from my main app. I set up everything but whatever I do, as soon as the remote gets fetched my application keeps on refreshing infinitely. Here my webpack configurations:

    SHELL:

    const { withModuleFederationPlugin, shareAll } = require('@angular-architects/module-federation/webpack');


    const config = withModuleFederationPlugin({
    name: 'host',
    exposes: {},
    remotes: {
    blog: 'blog@localhost:4201/remoteEntry.js',
    },
    shared: {
    }
    });

    config.output.uniqueName = 'shell';
    config.optimization.runtimeChunk = false;

    module.exports = config;


    REMOTE:

    const { withModuleFederationPlugin } = require('@angular-architects/module-federation/webpack');

    const config = withModuleFederationPlugin({
    name: 'blog',
    filename: 'remoteEntry.js',
    exposes: {
    './BlogLandingPageComponent': './projects/blog/src/app/blog/blog-landing-page/blog-landing-page.component',
    './BlogService': './projects/blog/src/app/blog/blog.service',
    },
    shared: {
    },
    remoteType: 'var',
    library: {
    type: 'var',
    name: 'blog'
    },

    });

    config.output = {
    chunkFormat: 'array-push',
    chunkLoading: 'jsonp',
    uniqueName: 'blog',
    publicPath: "auto", // Use auto public path for dynamic loading
    scriptType: 'text/javascript'
    };

    config.optimization = {
    runtimeChunk: false,
    };

    module.exports = config;



    Then, in my main.ts I try to initialize the remote like:

    Promise.all([
    loadRemoteEntry({
    type: 'script',
    remoteEntry: "http://localhost:4201/remoteEntry.js",
    remoteName: 'blog'
    }),
    ])
    .catch((err) => console.error('Error loading remote entries', err))
    .then((val) => {

    console.log('Remote entry loaded successfully:', val);

    // Check if the remote container is available
    if (window['blog']) {
    console.log('✅ Remote container "blog" is available:', window['blog']);
    } else {
    console.error('❌ Remote container "blog" is NOT available!');
    }

    if (document.readyState === 'complete') {
    bootstrap();
    } else {
    document.addEventListener('DOMContentLoaded', bootstrap);
    }
    })


    Commenting out the loadRemoteEntry method the refresh loop disappears. Is it an issue of hmr (hot module reloading)?

    Continue reading...

Compartilhe esta Página