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.

Federated Modules: Dynamic Remotes with synchronous imports

See original GitHub issue

Feature request

What is the current behavior? Using code from https://github.com/webpack/webpack/issues/11033 it is possible to load code in with dynamic urls asynchronously, however the given solution does not work with ‘synchronous’ imports for example:

import urls from "remoteModule/constants";

async function getSomething(params) {
  // ...Other processing
  return fetch(urls.aThing);
}

The code above would have to be converted to:

async function getSomething(params) {
  const { aThing } = await someKindOfDynamicLoading("remoteModule/constants");
    // ...Other processing
  return fetch(urls.aThing);
}

This doesn’t seem ideal especially for non-jsx code or ‘middleware-like’ code.

What is the expected behavior? See above?

What is motivation or use case for adding/changing the behavior? Not all code needs/wants the async loading of code to be ‘apparent’ like the example above but another example might be a set of constants that builds off another set of constants.

How should this be implemented in your opinion? I’m not sure to be honest, I would imagine something would ‘hook’ into the webpack internals before the async boundary for example:

(async () => {
  await loadModules();
  import("./index");
})();

Are you willing to work on this yourself? Maybe, but I would require quite a bit of assistance as I’m unfamiliar with webpack internals.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:47 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Guriqbal-Singh-Alidacommented, Jan 15, 2021

@jacob-ebey @ScriptedAlchemy issue solved. To explain when we provide multiple entry points, the each entry gets its own runtime by default(https://webpack.js.org/configuration/optimization/#optimizationruntimechunk). Since hooks and react components must share runtime we had to split react and vendor as separate common chunks and configure runtimeChunk as single

entry: {
      main: './src/index',
      'library-loader': {
        import: `${path.resolve(__dirname, 'src', 'startup.js')}`,
        library: {
          type: 'var',
          name: 'LIBRARY_LOAD',
        },
      },
    },
    externals: [
      {
        'library-loader': `promise LIBRARY_LOAD.library`,
      },
    ],
  optimization: {
    splitChunks: {
        chunks: 'all',
      },
    runtimeChunk: 'single',
  }

Thanks for all the support you guys provided

2reactions
ScriptedAlchemycommented, Jul 13, 2022

promise new promise syntax or pass remote an array or valid options, like remote1: [global@url,global@otherUrl]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module Federation - webpack
Loading remote modules is considered an asynchronous operation. ... to containers as externals and allows to import remote modules from these containers.
Read more >
Tutorial - A Guide to Module Federation for Enterprise
Module Federation allows a JavaScript application to dynamically load code from another application and in the process, share dependencies. This ...
Read more >
4 Ways to Use Dynamic Remotes in Module Federation
Dynamic Remotes in Webpack Module Federation. Luckily Webpack Module Federation supports dynamically defining URLs for our remote applications.
Read more >
How to Use Module Federation with Re.Pack 3 | blog {callstack}
The host app can only import remote modules and cannot have pre-defined 'exposes' or 'remotes' properties in Webpack config. However, MFEs can ...
Read more >
Microfrontends with Module Federation: What, Why, and How
The Host will consume and render the exposed components by the Remote Federated Module. In the previous example, MF2 is the container and...
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