Closed debugpai closed 2 years ago
Found out it is possible to do this. No special changes required. Also it is resolved at runtime so it would always get the fresh version of remoteEntry
file
Hi @debugpai.Can you pls tell how to fetch on server side without filesystem?
Hey @ajayjaggi. My bad. This feature is not possible on the server. From the server remoteEntry
file can only be accessed from the filesystem. Unfortunately the open source part of module federation only solves for client side rendering properly.
I guess it's possible to have a remote entry on the server as well, just need some workaround: Imagine there is two server, one provider(the one sharing the component) and one consumer server.
This is a very backward thinking approach and I dont think it's a very good solution
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:
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 webpack/webpack#12084
This is probably what @jacob-ebey's WebpackNodeHttpChunkLoadingPlugin
does here https://github.com/jacob-ebey/ssr-react-streaming-example/blob/main/ssr_react_streaming_example_a/webpack.config.js#L48-L50
@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.
@jacob-ebey I have to ask it: by any chance do you have plans to open source WebpackNodeHttpChunkLoadingPlugin
?
My problem with file system remote loading is: 1) can't have a distributed system for host and remotes. 2) I have to restart Next.js server (host) in order to get a fresh remote after making some changes on my remote (not sure if it's a FS issue - probably it's a webpack in-memory cache that I didn't figure out yet)
@estevaolucas I do not have plans at the moment, but with some of the other things I'm working on, it may come as part of those. Keep an eye on https://github.com/jacob-ebey/pwrc-react
Cool. I'm watching PWRC's repo since you've announced it on your Twitter 😬
It was a total surprise to me that you can't fetch from the server-side. I didn't think it's clear in the (tiny amount) of documentation.
When I read the examples, I thought they had filesystem references just for convenience of writing the example, not that it just wasn't possible for them to be fetched remotely. The error message I got when I tried it didn't give the vaguest hint at the underlying problem, so I spent at least half a day thinking I was doing something wrong.
Hello, is there now an open source solution ?
You can check https://github.com/telenko/node-mf by @telenko
Check out https://github.com/module-federation/MicroLib/blob/master/webpack/fetch-remotes.js
On Jun 25, 2021, at 5:16 AM, Valentin Semirulnik @.***> wrote:
You can check https://github.com/telenko/node-mf https://github.com/telenko/node-mf by @telenko https://github.com/telenko — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/module-federation/module-federation-examples/issues/399#issuecomment-868394943, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJI3W3QFAWJE6NOU5KS2RZ3TURJOHANCNFSM4SBSAZLQ.
There is an official streaming solution for node but its proprietary at the moment.
On Jun 25, 2021, at 5:16 AM, Valentin Semirulnik @.***> wrote:
You can check https://github.com/telenko/node-mf https://github.com/telenko/node-mf by @telenko https://github.com/telenko — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/module-federation/module-federation-examples/issues/399#issuecomment-868394943, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJI3W3QFAWJE6NOU5KS2RZ3TURJOHANCNFSM4SBSAZLQ.
We have multiple streaming solutions but only the worst will be publicly available, our older tech will be commercial and our latest innovation is patented and will require licenses or utilization of a SaaS
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.