Not possible to extract MF dynamic loading code to util library
See original GitHub issueIn order to dynamically load remote modules I have created the following “importRemote” function:
import script from "scriptjs";
const loadEntryPoint = url =>
new Promise(resolve => {
script.urlArgs(`t=${new Date().getTime()}`);
script(url, () => resolve());
});
// Dynamically import a remote module using Webpack's loading mechanism:
// https://webpack.js.org/concepts/module-federation/
const importRemote = async (url, scope, module) => {
if (!window[scope]) {
//Get the remote entry point:
await loadEntryPoint(`${url}/remoteEntry.js`);
if (!window[scope]) {
return Promise.reject(new Error(`${scope} could not be located!`));
}
// Initializes the share scope. This fills it with known provided modules from this build and all remotes
await __webpack_init_sharing__("default");
// Initialize the container, it may provide shared modules
await window[scope].init(__webpack_share_scopes__.default);
}
const moduleFactory = await window[scope].get(
module.startsWith("./") ? module : `./${module}`,
);
return moduleFactory();
};
export default importRemote;
I use this like React.lazy(()=>importRemote(url, scope, module))
This code is used in several projects so I want to extract the importRemote module to an external util library but I can’t because __webpack_init_sharing__
and __webpack_share_scopes__
are compilation scope variables from the project in which the module is located. If I move this code to a library and import it from there it doesn’t work because it seems that the scope variables are taken from the library’s build instead. Is there a way to achieve this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:38 (25 by maintainers)
Top Results From Across the Web
How to load JAR files dynamically at Runtime? - Stack Overflow
It will dedicate a class loader for the jar to make sure there are no library conflicts. Users will be able to create...
Read more >module-federation/nextjs-mf - npm
Ive added a util for dynamic chunk loading, in the event you need to load remote containers dynamically. InjectScript. import { injectScript } ......
Read more >CEELOAD macro — Dynamically load a Language ... - IBM
CEELOAD is used to dynamically load a Language Environment-conforming routine. ... If MF=I or MF=L, you must specify either NAME or NAMEADDR, but...
Read more >Chapter 3. Class Loading and Modules Red Hat JBoss ...
A dynamic module can declare dependencies in the deployment's MANIFEST.MF or jboss-deployment-structure.xml deployment descriptor. Implicit Dependencies.
Read more >3 ways to solve java.lang.NoClassDefFoundError in Java J2EE
Just thought I'd share that it's also worth checking permissions on the class libraries your application is loading. Incorrect user permissions (for instance ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I currently have all dynamic loading abstracted to a npm package. Build it with Babel or something standard. It should work
Make npm package a webpack build itself. Then it loads its own remote as needed if you don’t register the remote in your main build