question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The plugin doesnt work with module federation

See original GitHub issue

Bug report

The plugin doesnt work with module federation. When build the styles of the application host, an error is thrown.

ERROR in 4565.css
(0 , _identifier.getUndoPath) is not a function
TypeError: (0 , _identifier.getUndoPath) is not a function
at MiniCssExtractPlugin.renderContentAsset 

“mini-css-extract-plugin”: “2.3.0”, “webpack-5”: “npm:webpack@5.53.0”,

Actual Behavior

Build fall with Error

Expected Behavior

Application will build without error

How Do We Reproduce?

// npm alias
const webpack = require('webpack-5');
const ModuleFederationPlugin = require('webpack-5').container.ModuleFederationPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');

const { join } = require('path');

module.exports = {
    entry: './src/indexMf',
    devServer: {
        contentBase: join(__dirname, 'public'),
        port: 7777,
        historyApiFallback: true,
        proxy: [
            {
                context: ['/api', '/uaa'],
                target: URL',
                changeOrigin: true,
            },
        ],
    },
    output: {
        filename: '[name].[contenthash:8].bundle.js',
        publicPath: '/',
        assetModuleFilename: 'resources/[hash][ext][query]',
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js'],
        alias: {
            src: join(__dirname, 'src'),
        },
    },
    module: {
        rules: [
            {
                test: /bootstrap\.tsx$/,
                loader: 'bundle-loader',
                options: {
                    lazy: true,
                },
            },
            {
                test: /\.tsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                options: {
                    presets: [
                        '@babel/preset-env',
                        [
                            '@babel/preset-react',
                            {
                                runtime: 'automatic',
                            },
                        ],
                        '@babel/preset-typescript',
                    ],
                    plugins: [
                        '@babel/plugin-proposal-class-properties',
                        [
                            '@fcc/babel-plugin-jsx-fingerprint',
                            {
                                key: 'marker',
                                ignore: ['Fragment', 'IntlProvider', 'StylesProvider'],
                            },
                        ],
                        [
                            'babel-plugin-styled-components',
                            {
                                ssr: false,
                                pure: true,
                                minify: true,
                                transpileTemplateLiterals: true,
                                displayName: false,
                                fileName: false,
                            },
                        ],
                    ],
                },
            },
            {
                test: /\.css$/i,
                use: [MiniCssExtractPlugin.loader, 'css-loader'],
            },
            {
                test: /\.svg$/i,
                type: 'asset/resource',
                use: 'svgo-loader',
            },
            {
                test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
                type: 'asset/resource',
            },
        ],
    },
    plugins: [
        new MiniCssExtractPlugin(),
        new webpack.ProvidePlugin({
            React: 'react',
        }),
        new webpack.DefinePlugin({
            'process.env.PROXY_USE_PREVIEW': process.env.PROXY_USE_PREVIEW,
        }),
        new ModuleFederationPlugin({
            name: 'app1',
            remotes: {
                ClientTariffs: 'app2@http://localhost:3000/remoteEntry.js',
            },
            shared: [{ react: { singleton: true }, 'react-dom': { singleton: true } }],
        }),
        new HtmlWebpackPlugin({
            title: 'Corporate CRM',
            filename: './index.html',
            favicon: './public/favicon.ico',
            templateParameters: {
                PUBLIC_URL: '',
            },
        }),
        new CopyPlugin({
            patterns: [
                { from: 'public/resources', to: 'resources' },
                { from: 'public/manifest.json', to: './' },
                { from: 'public/robots.txt', to: './' },
            ],
        }),
    ],
};

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Sep 24, 2021

You have mixed verisons of webpack, it breaks some resolutions, please create different directory with package.json and move all webpack v5 deps there and run build script from this directory

0reactions
popuguytheparrotcommented, Sep 24, 2021

i need two version of webpack and i building MF this command

"build": "WEBPACK_PACKAGE=webpack-5 webpack --mode=production --config ./webpack.config.js",
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Webpack 5] Module Federation plugin does not work #186
Current behavior: Once configuring Webpack Federation Module for two Aurelia projects (one is a host and another one is a remote component), the ......
Read more >
Webpack 5 Module Federation throwing error Module doesn't ...
I am trying to build a remote/host sample MFE using Single SPA with Module Federation feature from WebPack 5. but I am getting...
Read more >
ModuleFederationPlugin - webpack
The ModuleFederationPlugin allows a build to provide or consume modules with other independent builds at runtime. const { ModuleFederationPlugin } ...
Read more >
Problem using ES modules in webpack module federat...
I am having serious trouble running angular application that uses webpack module federation remote entries with esri JS api ES modules.
Read more >
Module Federation Series Part 1: A Little in-depth
When you research approaches for building micro frontends, you would constantly see a module federation which is a new game changer plugin. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found