nrwl / nx

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

Module Federation SSR error: "Shared module is not available for eager consumption" #27000

Open S-FurmanBSF opened 4 months ago

S-FurmanBSF commented 4 months ago

Current Behavior

This issue exhibits the same behavior described in https://github.com/nrwl/nx/issues/14428. However, the solutions provided there do not seem to work on either Windows or macOS so I decided to open new issue. I couldn't even follow steps from your SSR tutorial. https://nx.dev/recipes/angular/module-federation-with-ssr

Expected Behavior

The code from tutorial should work.

GitHub Repo

No response

Steps to Reproduce

  1. Follow steps from tutorial: https://nx.dev/recipes/angular/module-federation-with-ssr

Nx Report

Node   : 20.11.1
OS     : win32-x64
npm    : 10.2.4

@nx/angular        : 19.5.0
@nx/devkit         : 19.5.0
@nx/eslint-plugin  : 19.5.0
@nrwl/tao          : 19.5.0
@nx/web            : 19.5.0
@nx/webpack        : 19.5.0
typescript         : 5.5.3

Failure Logs

Depending on the OS and nx version I get this errors:

**Windows ("nx": "19.5.0" -> from above nx report):**
Error:
        The loadShareSync function was unable to load @angular/common. The @angular/common could not be found in checkout.
        Possible reasons for failure:

        1. The @angular/common share was registered with the 'get' attribute, but loadShare was not used beforehand.

        2. The @angular/common share was not registered with the 'lib' attribute.

**windows("nx": "18.0.8"):**
if(typeof factory !== "function") throw new Error("Shared module is not available for eager consumption: " + id);
                                                                          ^

Error: Shared module is not available for eager consumption: 5538

**mac("nx": 18.0.8):**
SyntaxError: Unexpected token '<'
    at new Script (node:vm:99:7)
    at createScript (node:vm:255:10)
    at Object.runInThisContext (node:vm:303:10)
    at <anonymous> (./webpack/runtime/readFile%20chunk%20loading:51:1)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  message: 'Loading script failed.\n' +
    "(Unexpected token '<': http://localhost:4202/server/remoteEntry.js)",
  name: 'ScriptExternalLoadError'

Package Manager Version

No response

Operating System

Additional Information

No response

SiimTa commented 3 days ago

Any updates on this? :) Still replicating it in 20.x.x.