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.

Fetching remoteEntry.js file from a remote source on the server

See original GitHub issue

Hey everyone, First of all thanks a lot for the amazing work on module federation. I was wondering if it is possible to fetch the remoteEntry.js file from a remote source on the server. I know for client this is possible and was wondering if the same was possible on the server instead of fetching from the filesystem.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
7rulnikcommented, Dec 14, 2020

It’s possible. You can do it in this way:

   const remote = `new Promise(async resolve => {
  const content =  await someFetchFunction('http://hostname/appB/b-entry.js')
  const chunk = {}
  require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})')(chunk, require, 'some-fake-path', 'b-entry.js');
  resolve(chunk)
})`

    new webpack.container.ModuleFederationPlugin({
      remotes: {
        'b-entry': `promise ${remote}`
      },
    }),

Logic with require('vm') taken from webpack async-node target. Note that someFetchFunction should be defined somewhere in user-land code.

But it doesn’t solve the problem at all because you will need a way to fetch remote chunks via HTTP. To do this you have 2 ways:

  1. Teach webpack to fetch chunks over http. It’s pretty risky and requires a custom chunk loading runtime. I will open-source it later. See https://github.com/webpack/webpack/issues/12084
  2. Fetch and save remote chunks on same file system (or use some shared FS)
1reaction
jacob-ebeycommented, Jan 4, 2021

@7rulnik pretty much nailed what the http chunk loading plugin does. There are some other changes needed in the webpack chunk loading runtime that’s embeded into the remote entry otherwise it will try to load chunks from local disk instead of over the network.

Read more comments on GitHub >

github_iconTop Results From Across the Web

remoteEntry.js was not being fetched despite being defined?
js from subA and subB are being fetched by host, despite I did not import any source code from subB , the behaviour...
Read more >
Tutorial - A Guide to Module Federation for Enterprise
Fetch configuration files and assign them to global variables to be used ... Note: remoteEntry.js is considered a local chunk in the remote...
Read more >
Module Federation - webpack
This object is used as a shared scope in the remote container and is filled with the provided modules from a host. It...
Read more >
Setting up remote components and services with webpack ...
Setting up Federated remote application. Install webpack 5 in your application. npm i -D webpack webpack-cli webpack-dev-server. 2.
Read more >
Micro-frontends: Module Federation with WebPack 5
We also need to specify the remoteEntry.js file from the remote host: <!-- public/index.html (fragment)--> ... < ...
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