react-refresh-webpack-plugin icon indicating copy to clipboard operation
react-refresh-webpack-plugin copied to clipboard

Micro frontends and duplicate moduleId

Open jamime opened this issue 2 years ago • 2 comments

In my micro frontend I have a html page with multiple scripts included. Each of these scripts are created by a different webpack config.

In development mode webpack uses the NamedModuleIdsPlugin. This generates module id's such as src/index.tsx. https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/ids/NamedModuleIdsPlugin.js#L43

When I save either project, all instances of src/index.tsx are replaced with the same component. For example, I would end up with two applications instead of an application and a nav bar. Or I could end up with two nav bars.

I made a patch in NamedModuleIdsPlugin to prefix the uniqueName to the module Id.

(m) =>`${compiler.options.output.uniqueName}: ${getShortModuleName(m, context, root)}`,

Is this something that we could handle in react-refresh-webpack-plugin or would this be better to fix in webpack?

jamime avatar Aug 05 '22 07:08 jamime

I think this is a webpack related issue. Normally modules from different webpack runtimes shouldn't interfere with each other. Did all your projects have the same name in package.json?

INCHMAN1901 avatar Aug 17 '22 06:08 INCHMAN1901

Did all your projects have the same name in package.json?

Different project name but same file name.

jamime avatar Dec 20 '22 15:12 jamime