Skip to content

@nx/module-federation "getDependencies" does not support cargo externalNodes #32819

@markusvoelk-zr

Description

@markusvoelk-zr

Current Behavior

The official nx documentation mentions to use @monodun/rust package for building cargo packages.
This nx plugin adds externalNodes "cargo:".
These externals are not supported by the @nx/module-federation plugin. Especially the "getDependencies" method threats the cargo externals as workspace packages and crashes at

root: projectGraph.nodes[dependency.target].data.root,

This issue is related to Cammisuli/monodon#73 but I think the @nx/module-federation should get a fix

Expected Behavior

@nx/module-federation works with at least cargo and npm packages

  • A further optimization would be a configurable behaviour of the getDependencies method.
  • Or to allow plugins (like @monodun/rust) to extend workspace wide configuration (e.g. externalsPrefixes)
  • Or to dynamically extract the externals prefixes from the list of nodes

GitHub Repo

No response

Steps to Reproduce

  1. Walk through https://nx.dev/showcase/example-repos/add-rust (the cats library is sufficient)
  2. Update the library name in Cargo.toml to libs_cats_cats
  3. npm i @nx/module-federation @nx/devkit
  4. Create and run the file repro.js; content:
const { getDependentPackagesForProject } = require("@nx/module-federation");
const { readCachedProjectGraph } = require("@nx/devkit");

const projectGraph = readCachedProjectGraph();
getDependentPackagesForProject(projectGraph, "libs_cats_cats");

Nx Report

Node           : 22.17.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.9.2

nx                     : 21.5.3
@nx/js                 : 21.5.3
@nx/workspace          : 21.5.3
@nx/devkit             : 21.5.3
@nx/module-federation  : 21.5.3
@nx/web                : 21.5.3
typescript             : 5.9.2
---------------------------------------
Registered Plugins:
@monodon/rust
---------------------------------------
Community plugins:
@monodon/rust : 2.3.0
---------------------------------------
Cache Usage: 0.00 B / 95.21 GB

Failure Logs

> node .\repro.js
acme\node_modules\@nx\module-federation\src\utils\dependencies.js:29
                root: projectGraph.nodes[dependency.target].data.root,
                                                            ^

TypeError: Cannot read properties of undefined (reading 'data')
    at acme\node_modules\@nx\module-federation\src\utils\dependencies.js:29:61
    at Array.forEach (<anonymous>)
    at collectDependencies (acme\node_modules\@nx\module-federation\src\utils\dependencies.js:22:45)
    at getDependentPackagesForProject (acme\node_modules\@nx\module-federation\src\utils\dependencies.js:8:49)
    at Object.<anonymous> (acme\repro.js:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1730:14)
    at Object..js (node:internal/modules/cjs/loader:1895:10)
    at Module.load (node:internal/modules/cjs/loader:1465:32)
    at Function._load (node:internal/modules/cjs/loader:1282:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)

Node.js v22.17.0

Package Manager Version

npm 10.9.2

Operating System

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

Additional Information

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions