Skip to content

Conversation

@mtqperson
Copy link
Contributor

Ideally we want to use ESM, but the reality is that @fluentui/react-theme (and other Fluent packages) ESM lacks Node.js compliance (missing .js extensions) - it works in bundlers but not in Node.js.

This means downstream tools are forced to use a CJS bundler, which can require Fluent UI from node_modules because Fluent has CJS exports as a fallback.

However, this package doesn't provide CJS, so such a downstream bundler cannot require it and must bundle our source into its own dist instead.

By adding CJS here, downstream libraries can externalize us from node_modules, reducing their bundle sizes. Otherwise we become a nested dependency.

  • Add build:cjs script and lib-commonjs output
  • Update exports with require condition
  • Remove "type": "module" for dual-format semantics

@mtqperson mtqperson marked this pull request as ready for review November 24, 2025 15:31
@mtqperson mtqperson requested a review from a team as a code owner November 24, 2025 15:31
Copy link
Contributor

@NiklasRamstrom NiklasRamstrom left a comment

Choose a reason for hiding this comment

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

Looks good to me, with my limited knowledge of ESM vs CJS :)
Did a quick test locally from the theme-package on the branch and did not see any problems using the ESM part.

Ideally we want to use ESM, but the reality is that
@fluentui/react-theme (and other Fluent packages) ESM lacks Node.js
compliance (missing .js extensions) - it works in bundlers but not in
Node.js.

This means downstream tools are forced to use a CJS bundler, which can
`require` Fluent UI from `node_modules` because Fluent has CJS exports
as a fallback.

However, this package doesn't provide CJS, so such a downstream bundler
cannot `require` it and must bundle our source into its own dist instead.

By adding CJS here, downstream libraries can externalize us from
node_modules, reducing their bundle sizes. Otherwise we become a nested
dependency.

- Add build:cjs script and lib-commonjs output
- Update exports with require condition
- Remove "type": "module" for dual-format semantics
@lekoaf lekoaf merged commit e9f7bd6 into main Nov 26, 2025
8 checks passed
@lekoaf lekoaf deleted the mtq/add-cjs branch November 26, 2025 10:25
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.

4 participants