Skip to content

Esbuild in Native Federation fails to resolve shared/exposed packages with .mjs entrypoints #994

@Daniel4o

Description

@Daniel4o

With what library do you have an issue?

native-federation

Reproduction of the bug/regression with instructions

  1. Create a Native Federation remote/shell.
  2. Add a shared/exposed dependency whose entrypoint is published as index.mjs (e.g. some-lib/dist/icons).
  3. Run npm install.
  4. Run the NF build (e.g. npx nx build <remote>).
    -> Esbuild aborts with Could not resolve "<package>/dist/icons".

Expected behavior

Esbuild should resolve .mjs entrypoints of shared/exposed packages without manual patching; the build should succeed.

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

  • @angular-architects/native-federation: 20.1.7
  • Angular: 20.3.x
  • Node: v24.10.0 (also reproducible on Node 20)
  • OS: macOS (Apple Silicon)
  • Browser: Chrome (n/a for build issue)

Other information

Link to PR resolving the issue: #993
Link for ESBuild docs for resolveExtensions property: https://esbuild.github.io/api/#resolve-extensions

From ESBuild docs:

The resolution algorithm used by node supports implicit file extensions. You can require('./file') and it will check for ./file, ./file.js, ./file.json, and ./file.node in that order. Modern bundlers including esbuild extend this concept to other file types as well. The full order of implicit file extensions in esbuild can be customized using the resolve extensions setting, which defaults to .tsx,.ts,.jsx,.js,.css,.json.
Note that esbuild deliberately does not include the new .mjs and .cjs extensions in this list. Node's resolution algorithm doesn't treat these as implicit file extensions, so esbuild doesn't either. If you want to import files with these extensions you should either explicitly add the extensions in your import paths or change this setting to include the additional extensions that you want to be implicit.

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

  • Yes
  • No

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions