fix(esbuild): fix esbuild 0.25.0 compatibility and remote module loading#4255
Conversation
🦋 Changeset detectedLatest commit: 8eff075 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
✅ Deploy Preview for module-federation-docs ready!
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 <noreply@anthropic.com>
41b3cea to
57b0f91
Compare
There was a problem hiding this comment.
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 deprecatedwatchoption - 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.
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 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Bundle Size Report1 package(s) changed, 35 unchanged.
Total dist: 4.96 MB (+3.1 kB (+0.1%)) |
Summary
Fixed two critical issues preventing the
apps/esbuilddemo from working:1. esbuild 0.25.0 Watch Mode Compatibility
apps/esbuild/build/build-common.jswatchoption frombuild()APIesbuild.context()withctx.watch()for watch mode instead of passingwatchoption tobuild()2. Import Map Registration for ESM Remote Modules
packages/esbuild/src/adapters/lib/containerReference.tsmfe1/component) were failing with "Unable to resolve specifier" errorruntimePlugin.init()was looking formoduleMapin the host scope instead of fetching it from the remote module exportsruntimePlugin.init()ran after bootstrap imports needed theminitializeSharingbut 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
pnpm nx run esbuild:buildcd apps/esbuild && pnpm run buildpnpm run start:remoteandpnpm run start:hostTypes of Changes
🤖 Generated with Claude Code