Skip to content

fix: resolve named CommonJS imports in dev-server bundling#89

Open
Aukevanoost wants to merge 1 commit into
mainfrom
issues/83
Open

fix: resolve named CommonJS imports in dev-server bundling#89
Aukevanoost wants to merge 1 commit into
mainfrom
issues/83

Conversation

@Aukevanoost

@Aukevanoost Aukevanoost commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #83

This pull request introduces comprehensive improvements to the handling of CommonJS (CJS) and ECMAScript Module (ESM) interop in the node-modules-bundler for esbuild. It adds robust detection and synthetic export generation for named exports from CJS modules, ensuring that named imports work correctly across module boundaries, especially when using module federation or import maps. The update also includes extensive unit tests for the new logic.

CommonJS/ESM Interop Enhancements

Build Pipeline and Transform Logic

  • Updated the esbuild plugin setup to ensure the new CJS named exports plugin precedes the CommonJS plugin, so it takes precedence for entry-point resolution ([src/tools/esbuild/node-modules-bundler.tsR414-R416]).
  • Refactored the transform skip logic into a new canSkipTransform function, which only skips .mjs files that don't need linking and when advanced optimizations are disabled [1]], [2]]).

Testing

  • Added comprehensive unit tests for all new helper functions and plugin logic in node-modules-bundler.spec.ts, covering edge cases and ensuring correctness for CJS/ESM detection, export generation, and error handling [1]], [2]]).

These changes significantly improve the reliability and correctness of named import handling from CJS modules in esbuild-based builds, especially in federated or import map scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng serve fails with "No matching export" for named CommonJS imports in shared deps (ng build works)

1 participant