#37209·nx

extractLicenses: true fails the build with "ENOENT: scandir ''" for @nx/rspack apps using Module Federation

Author: AndreasJagiella-EHCreated Sep 28, 2026Updated Sep 28, 2026

Current Behavior

Setting extractLicenses: true on NxAppRspackPlugin in an Nx rspack application that also uses Module Federation (NxModuleFederationPlugin) always fails the build:

× caused by plugins in Compilation.hooks.processAssets
  ╰─▶ × Error: ENOENT: no such file or directory, scandir ''

The same app builds fine with extractLicenses unset.

Root cause

@nx/rspack wires up license-webpack-plugin for this option with hardcoded options (packages/rspack/src/plugins/utils/apply-base-config.ts, the if (options.extractLicenses) branch). That plugin is webpack-only and cannot parse rspack's Module Federation module identifiers:

  1. rspack injects the Module Federation runtime as an inline data: module, and the module identifier carries the loader prefix:

    builtin:swc-loader??ruleSet[1].rules[2].use[0]!data:text/javascript,import __module_federation_bundler_runtime__ from "..."
  2. In license-webpack-plugin's WebpackInnerModuleIterator.getActualFilename, the guard filename.indexOf('data:') === 0 is checked before the loader-split branch. Because rspack prefixes the loader, the identifier does not start with data:, so the guard misses.

  3. The next branch, if (filename.indexOf('!') > -1), splits on ! and returns everything after the last !. The inlined federation runtime source itself contains !==, so the returned "filename" is a fragment of JavaScript source rather than a path.

  4. That fragment contains no path separator, so PluginFileHandler.findModuleDir computes dirOfModule = ''. dirContainsValidPackageJson('') then reads package.json relative to the current working directory — and Nx runs rspack with cwd set to the project root — so it "finds" a valid package.json and returns { directory: '' } with that package's name.

  5. LicenseTextReader.readLicense calls listPaths('') → scandir('') → ENOENT, thrown inside processAssets, which fails the build.

Two consequences beyond the crash: there is no way to work around it, because Nx does not expose the plugin's options (excludedPackageTest, modulesDirectories, licenseTextOverrides, …); and step 4 means a module can be silently attributed to whatever package sits at the cwd, so even where it does not crash the output can name the wrong package.

Worth noting that license-webpack-plugin is effectively unmaintained — latest release is 4.0.2, published 2022-06-19 — so a fix upstream is unlikely.

Expected Behavior

extractLicenses: true either produces 3rdpartylicenses.txt for rspack + Module Federation apps, or at minimum does not crash the build. Options:

  • pass through license-webpack-plugin options from the executor/plugin options so users can set excludedPackageTest / modulesDirectories themselves;
  • supply rspack-aware defaults that tolerate module identifiers which are not filesystem paths;
  • or document that the option is unsupported with rspack + Module Federation.

Manually instantiating LicenseWebpackPlugin with an excludedPackageTest that filters out the phantom module does produce a correct, complete 3rdpartylicenses.txt, so the underlying extraction does work with rspack — only Nx's hardcoded configuration is at fault.

Steps to Reproduce

  1. Create an Nx workspace with the rspack bundler and a React host + remote (Module Federation), e.g. create-nx-workspace --preset=react-monorepo --bundler=rspack, then nx g @nx/react:host shell --remotes=remote1.
  2. In the remote's (or host's) rspack.config.ts, add extractLicenses: true to the NxAppRspackPlugin options.
  3. NODE_ENV=production nx build remote1.

The build fails with the scandir '' error above. Removing extractLicenses makes it pass again.

Note: this was traced in an existing rspack + Module Federation workspace rather than from a scaffolded reproduction repo, but the trigger is the Module Federation runtime module that NxModuleFederationPlugin itself injects plus the default builtin:swc-loader rule, so it should apply to any such setup. Plain rspack apps without Module Federation are unaffected.

Nx Report

Node   : 24.18.1
OS     : linux x64
pnpm   : 11.25.0

nx                     : 23.0.2
@nx/js                 : 23.0.2
@nx/devkit             : 23.0.2
@nx/eslint             : 23.0.2
@nx/jest               : 23.0.2
@nx/module-federation  : 23.0.2
@nx/react              : 23.0.2
@nx/rspack             : 23.0.2
@nx/web                : 23.0.2
@nx/workspace          : 23.0.2
typescript             : 5.9.2

Registered Plugins:
@nx/js/typescript
@nx/react/router-plugin
@nx/rspack/plugin
@nx/eslint/plugin
@nx/jest/plugin

Other relevant versions: @rspack/core 1.5.3, license-webpack-plugin 4.0.2 (transitive, via @nx/rspack), @module-federation/enhanced 2.9.0.

Failure Logs

[rspack-cli] [Error:   × caused by plugins in Compilation.hooks.processAssets
  ╰─▶   × Error: ENOENT: no such file or directory, scandir ''
      │     at WebpackFileSystem.listPaths (.../license-webpack-plugin/dist/WebpackFileSystem.js:78:24)
      │     at LicenseTextReader.readLicense (.../license-webpack-plugin/dist/LicenseTextReader.js:37:54)
      │     at PluginChunkReadHandler.processModule (.../license-webpack-plugin/dist/PluginChunkReadHandler.js:71:62)
      │     at .../license-webpack-plugin/dist/PluginChunkReadHandler.js:24:27
      │     at WebpackInnerModuleIterator.internalCallback (.../license-webpack-plugin/dist/WebpackInnerModuleIterator.js:39:13)
      │     at WebpackInnerModuleIterator.iterateModules (.../license-webpack-plugin/dist/WebpackInnerModuleIterator.js:21:9)
      │     at .../license-webpack-plugin/dist/PluginChunkReadHandler.js:20:39
      │     at WebpackChunkModuleIterator.iterateModules (.../license-webpack-plugin/dist/WebpackChunkModuleIterator.js:42:21)
] { code: 'GenericFailure' }

Operating System

Linux