module-federation / core

Module Federation is a concept that allows developers to share code and resources across multiple JavaScript applications
https://module-federation.io/
MIT License
1.4k stars 207 forks source link

Critical dependency warning in @module-federation/utilities due to dynamic import #2794

Open seshu-uggina opened 1 month ago

seshu-uggina commented 1 month ago

Describe the bug

I encountered a critical dependency warning related to a dynamic import while using the @module-federation/utilities package. This warning appears during the build process with Webpack.

WARNING in ../node_modules/@module-federation/utilities/dist/index.cjs.js 804:52-62 Critical dependency: the request of a dependency is an expression

Reproduction

Install @module-federation/utilities in your project. Configure Webpack to build the project. Run the build process. Observe the warning in the console output.

Used Package Manager

yarn

System Info

@module-federation/utilities version: 3.0.0 to 3.0.37

Validations

krau5 commented 1 month ago

+1

seshu-uggina commented 1 month ago

I have added tempaory fix in my appllication configuration to reslove this issue. here the code that i have added in my webpack configuration plugin section

new webpack.ContextReplacementPlugin(/@module-federation\/utilities/, path.resolve(__dirname, 'node_modules/@module-federation/utilities/dist/index.cjs'), { // Provide context options if needed },),

ScriptedAlchemy commented 1 month ago

Dont use utilities, its dead, use the runtime package and loadRemote etc

krau5 commented 1 month ago

@ScriptedAlchemy could it be a good idea to add some workaround/examples for loading the exact module via loadRemote? It seems, that documentation is not that clear for everyone. I am using the module from the remote entry, which I am currently loading via importRemote. However, I have not figured out how to use the loadRemote for my case, and I have not found any examples on github as well.

ScriptedAlchemy commented 1 month ago

the module federation website shows examples of the runtime. Also dynamic remote or advanced api should as well in examples repo.

ScriptedAlchemy commented 1 month ago

https://github.com/module-federation/module-federation-examples/tree/master/dynamic-system-host https://module-federation.io/guide/basic/runtime.html