Dynamic import only work when direct passed named
See original GitHub issueHi i am working on a offline approach to use with module federation and to achieve this i must load and cache all the components from my remotes. But when i try to load the component with dynamic import and dynamic string, the webpack cant find it module. I am targeting to do
const modules = ["Cronograma", "Sampler", "Wrapper"]
modules.forEach(module => import(`cronograma/${module}`))
I saw it didnt work and try to simplify it in order to test. I’ve tried a simples dummy test like:
const moduleName = "cronograma/Cronograma";
import(moduleName);
At the browser i am getting the error:
src_bootstrap_js.js:2169 Uncaught (in promise) Error: Cannot find module ‘cronograma/Cronograma’
According with the Dynamic import specs it accepts a string, so it appears to be something related with module federation 😕
Here the full code of my test
// const modules = ["Cronograma", "Sampler", "Wrapper"]
const modules = ["Cronograma"]
setTimeout(() => {
//modules.forEach(module => import(`cronograma/${module}`)) Does not work either
console.log("Trying to import from string ")
const moduleName = "cronograma/Cronograma";
import(moduleName); //Dont work
setTimeout(() => {
console.log("Trying to import the same but directly string ")
import("cronograma/Cronograma"); // Work
console.log("Imported")
}, 1000)
}, 3000)
Above the screencapture of the browser (and the componented rendered using the plain import withtout the string)
I am letting something pass by? or should work in a different way with string dynamic imports with module federation?
Issue Analytics
- State:
- Created 2 years ago
- Comments:28 (24 by maintainers)
Top GitHub Comments
So I may have a way to do this now. It would involve inspecting the runtime module that creates this request, and see if it can take a dynamic expression for it.
@alessioerosferri we are willing to make it possible thru https://github.com/schirrel/extended-module-federation-plugin