Skip to content

Conversation

@Nsttt
Copy link
Contributor

@Nsttt Nsttt commented Dec 8, 2025

Summary

Fixed two critical issues preventing the apps/esbuild demo from working:

1. esbuild 0.25.0 Watch Mode Compatibility

  • File: apps/esbuild/build/build-common.js
  • Issue: esbuild 0.25.0 removed the watch option from build() API
  • Fix: Use esbuild.context() with ctx.watch() for watch mode instead of passing watch option to build()

2. Import Map Registration for ESM Remote Modules

  • File: packages/esbuild/src/adapters/lib/containerReference.ts
  • Issue: Remote module imports (mfe1/component) were failing with "Unable to resolve specifier" error
  • Root Causes:
    • The runtimePlugin.init() was looking for moduleMap in the host scope instead of fetching it from the remote module exports
    • Import map keys were using the host name instead of the remote name
    • The async registration in runtimePlugin.init() ran after bootstrap imports needed them
  • Fix: Added explicit synchronous import map registration in the host initialization code that runs after initializeSharing but before any code that imports from remotes. This ensures import maps are registered before es-module-shims tries to resolve remote module specifiers.

Test Plan

  • Build the esbuild package: pnpm nx run esbuild:build
  • Build the demo apps: cd apps/esbuild && pnpm run build
  • Start both servers: pnpm run start:remote and pnpm run start:host
  • Verify federated component loads at http://127.0.0.1:3000
  • Confirm no "Unable to resolve specifier" errors in console

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings December 8, 2025 15:52
@changeset-bot
Copy link

changeset-bot bot commented Dec 8, 2025

🦋 Changeset detected

Latest commit: 3793678

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@module-federation/esbuild Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Dec 8, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 3793678
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/6936f8669b1029000739478a
😎 Deploy Preview https://deploy-preview-4255--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

- Use esbuild context() API for watch mode (0.25.0 removed watch option)
- Enables proper build and watch functionality in apps/esbuild demo

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@Nsttt Nsttt force-pushed the Nsttt/test-esbuild-apps branch from 41b3cea to 57b0f91 Compare December 8, 2025 15:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses two critical issues in the esbuild integration: compatibility with esbuild 0.25.0's API changes and fixing remote module resolution to use runtime loading instead of import maps.

Key Changes:

  • Updated build script to use esbuild's context() API for watch mode instead of the deprecated watch option
  • Refactored remote module loading to use container.loadRemote() at runtime instead of relying on import maps

Reviewed changes

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

File Description
apps/esbuild/build/build-common.js Updated to use esbuild 0.25.0's context() API for watch mode, replacing the deprecated watch option in the build() call
packages/esbuild/src/adapters/lib/linkRemotesPlugin.ts Refactored virtual module generation to use runtime loadRemote() instead of import maps, removed obsolete federationRemote/ resolution handler

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Nsttt and others added 2 commits December 8, 2025 17:05
The import map registration was failing because:
1. The runtimePlugin was looking for moduleMap in the host scope instead of
   fetching it from the remote module exports
2. The import map key was using the host name instead of the remote name
3. The async registration in runtimePlugin.init() ran after bootstrap imports

This fix adds explicit synchronous import map registration in the host
initialization code that runs after initializeSharing but before any
code that imports from remotes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant