Skip to content

Native Federation build fails for sharedMappings when two assets share the same basename (media/duplicate.svg collision) #1087

@kitos13

Description

@kitos13

With what library do you have an issue?

native-federation

Reproduction of the bug/regression with instructions

I attached a minimal Nx repro. Steps:

  1. npm install
  2. npm run build:esbuild → succeeds
  3. npm run build:nf → fails

Failure:

Two output files share the same path but have different contents: media/duplicate.svg

The repo has a tiny shared library (dup-lib) in sharedMappings. Its styles reference two different SVG files with the same basename.

poc.zip

Expected behavior

Native Federation should not collapse distinct media files to the same emitted path. It should honor Angular’s media hashing behavior, or otherwise emit unique media filenames, so the build succeeds.

Versions of Native/Module Federation, Angular, Node, Browser, and operating system

Native Federation: 21.2.1
Angular: 21.1.5
Nx: 22.5.4
Node: v22.19.0
npm: 11.6.2
Browser: N/A (build-time failure, no browser needed)
OS: macOS 26.3.1 arm64

Other information

Plain Angular build passes; only the Native Federation build fails.
Possible cause: Native Federation’s esbuild adapter appears to emit media as media/[name], ignoring Angular outputHashing:
"media".

Was able to overcome this locally by using patch-package,
diff --git a/node_modules/@angular-architects/native-federation/src/utils/angular-esbuild-adapter.js b/node_modules/@angular-architects/native-federation/src/utils/angular-esbuild-adapter.js
index df55a09..bcaa7c3 100644
--- a/node_modules/@angular-architects/native-federation/src/utils/angular-esbuild-adapter.js
+++ b/node_modules/@angular-architects/native-federation/src/utils/angular-esbuild-adapter.js
@@ -113,7 +113,7 @@ async function runEsbuild(builderOptions, context, entryPoints, external, outdir
: await getTailwindConfig(searchDirectories);
const outputNames = {
bundles: '[name]',

  •    media: 'media/[name]',
    
  •    media: 'media/[name]-[hash]',
    
    };
    let fileReplacements;
    if (builderOptions.fileReplacements) {
    Not sure if this is the correct way to solve it.

I would be willing to submit a PR to fix this issue

  • Yes
  • No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions