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.

Server-side rendering does not work with Module Federation

See original GitHub issue

Bug report

What is the current behavior?

I am able to build and start the host and remote servers successfully, but I get this server error when loading the page in the browser. The browser remains spinning until I stop the server.

(node:66910) UnhandledPromiseRejectionWarning: Error: Cannot find module 'webpack/container/reference/remote'
Require stack:
- /Users/suhanwijaya/Desktop/wp5-ssr/host/build/server/bundle.js
while loading "./top-nav" from webpack/container/reference/remote
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.webpack/container/reference/remote (/Users/suhanwijaya/Desktop/wp5-ssr/host/build/server/bundle.js:171:18)
    at __webpack_require__ (/Users/suhanwijaya/Desktop/wp5-ssr/host/build/server/bundle.js:194:41)
    at handleFunction (/Users/suhanwijaya/Desktop/wp5-ssr/host/build/server/bundle.js:300:31)
    at /Users/suhanwijaya/Desktop/wp5-ssr/host/build/server/bundle.js:319:15
    at Array.forEach (<anonymous>)
    at Object.__webpack_require__.f.remotes (/Users/suhanwijaya/Desktop/wp5-ssr/host/build/server/bundle.js:282:36)
(node:66910) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:66910) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

If the current behavior is a bug, please provide the steps to reproduce.

Minimal reproducible repo: https://github.com/suhanw/wp5-ssr

I included a README for the instructions to run locally.

host server webpack config: https://github.com/suhanw/wp5-ssr/blob/main/host/webpack.server.config.js remote server webpack config: https://github.com/suhanw/wp5-ssr/blob/main/remote/webpack.server.config.js

remote exposes the component TopNav, and host consumes and imports TopNav in the App component, here: https://github.com/suhanw/wp5-ssr/blob/main/host/client/components/App/index.js#L3

If you comment out the line above, SSR works (i.e., the App component is rendered on server-side correctly).

PS: I was following this example by @ScriptedAlchemy.

What is the expected behavior?

host should be able to consume shared components exposed by remote for server-side rendering.

Other relevant information: webpack version: 5.12.1 Node.js version: 14.15.3 Operating System: MacOS Catalina 10.15.6 Additional tools: None

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jacob-ebeycommented, Jan 15, 2021

This is a simple case of misconfigured externals: https://github.com/suhanw/wp5-ssr/pull/1

No bug here, this issue can be closed.

I have submitted a PR to webpack-node-externals to try to avoid this issue in the future: https://github.com/liady/webpack-node-externals/pull/92

0reactions
alexander-akaitcommented, Jan 15, 2021

@jacob-ebey thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side rendering does not work with Module Federation
README has the instructions to run locally. I was following this example when creating this project. What is the current behavior? I am...
Read more >
Server-side rendering tactics for federated applications
What are the available techniques for SSR applications powered by Module Federation? There are a few to choose from, let's list them.
Read more >
SSR with Angular and Module Federation - Stack Overflow
The new version of @nguniversal/common@13.0.2 does not export the CustomResourceLoader so it cannot be modified for module federation use.. Do ...
Read more >
Module Federation, Next.js, and Server Side ... - YouTube
Your browser can't play this video. Learn more. Switch camera ... Module Federation, Next.js, and Server Side Rendering Livestream demo.
Read more >
Working on Federated SSR & Hot reloading production, in ...
Demo of hot reloadable production servers that use module federation and next.js. This video gives a sneak peek and reveals some of the ......
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