Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Module-Federation] Can't find module sdk/dist/dist/index.cjs.js #27964

Closed
1 of 4 tasks
KyorCode opened this issue Sep 17, 2024 · 2 comments · Fixed by #29104
Closed
1 of 4 tasks

[Module-Federation] Can't find module sdk/dist/dist/index.cjs.js #27964

KyorCode opened this issue Sep 17, 2024 · 2 comments · Fixed by #29104
Assignees
Labels

Comments

@KyorCode
Copy link

KyorCode commented Sep 17, 2024

Current Behavior

I followed the steps on https://nx.dev/recipes/react/module-federation-with-ssr to setup a basic SSR workspace. I removed the checkout remote and cleaned some stuff up. It was all working up until the point that I want to just render out the HTML provided by SSR, based upon a remote component.

If you run the nx run store:serve:development --verbose command and go to http://localhost:4200/v2 - you'll see that there is no output from the server. Just the error below. While I would just expect it the have the html output from the component wrapped in a <div id="root"></div>.

The normal http://localhost:4200 just works fine.

What I noticed in the error is that there is a double /dist/dist/ in there, which I presume to be a bug of some sorts.

Expected Behavior

Being able to output plain html from a SSR service.

GitHub Repo

https://github.com/KyorCode/nx-mf-test

Steps to Reproduce

  1. download / clone repo
  2. yarn / npm install
  3. run nx run store:serve:development --verbose

Nx Report

NX   Report complete - copy this into the issue template

Node           : 20.16.0
OS             : darwin-x64
Native Target  : x86_64-macos
npm            : 10.8.3

nx (global)        : 19.7.2
nx                 : 19.7.3
@nx/js             : 19.7.3
@nx/jest           : 19.7.3
@nx/linter         : 19.7.3
@nx/eslint         : 19.7.3
@nx/workspace      : 19.7.3
@nx/devkit         : 19.7.3
@nx/eslint-plugin  : 19.7.3
@nx/react          : 19.7.3
@nrwl/tao          : 19.7.3
@nx/web            : 19.7.3
@nx/webpack        : 19.7.3
typescript         : 5.5.4

Failure Logs

Error: Cannot find module '/Users/xxxx/Projects/xxx/my-test/node_modules/@module-federation/sdk/dist/dist/index.cjs.js'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1182:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:1170:15)
    at trySelf (node:internal/modules/cjs/loader:559:12)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1122:24)
    at Function.Module._load (node:internal/modules/cjs/loader:986:27)
    at Function.Module._load (/Users/xxx/Projects/xxx/my-test/node_modules/@nx/js/src/executors/node/node-with-require-overrides.js:18:31)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.29 (remoteEntry.js:480:18)
    at __webpack_require__ (remoteEntry.js:550:32) {
  code: 'MODULE_NOT_FOUND',
  path: '/Users/xxx/Projects/xxx/my-test/node_modules/@module-federation/sdk/dist/package.json'
}

Package Manager Version

4.5.0 ( yarn )

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

My end goal is to have module federated SSR service which just outputs the component HTML and returns it in a response. The reason is that this service is called by a CMS system and all the frontend/browser related stuff is handled there. Not in the SSR service.

@Coly010 Coly010 self-assigned this Sep 18, 2024
@Coly010 Coly010 added the scope: module federation Issues related to module federation support label Sep 18, 2024
@Coly010
Copy link
Contributor

Coly010 commented Sep 18, 2024

@KyorCode Thanks for raising this. I believe this is an issue on the Module Federation side. Good spot on the double dist/ in the string. I'll speak with Zack Jackson and take a look over on that repo to see if i can resolve this myself.

FrozenPandaz pushed a commit that referenced this issue Nov 28, 2024
…ues with eager sharing (#29104)

## Current Behavior
SSR with Module Federation frequently encounters issues related to the
eager resolution of shared packages.
This has resulted in numerous erroneous behaviours including but not
limited to:
- Failure to start server
- Failure to resolve remotes
- Failure to server render remotes

## Expected Behavior
Using the `'hoisted'` runtime provided by MF 2.0, we can ensure that SSR
for Module Federation runs in an async environment, removing the issues
surrounding eager consumption and resolution of shared modules.
In testing, this has fixed the issues outlined above

## Related Issue(s)

Fixes #27000
Fixes #27964

(cherry picked from commit 182b46c)
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants