nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.39k stars 2.33k forks source link

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

Open KyorCode opened 2 weeks ago

KyorCode commented 2 weeks ago

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

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 commented 2 weeks ago

@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.