-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Add exports field and build proper ES modules #745
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Netlify deploy preview |
michaldudak
force-pushed
the
esm-build
branch
from
October 31, 2024 12:25
59f88c1
to
80ffb32
Compare
github-actions
bot
added
PR: out-of-date
The pull request has merge conflicts and can't be merged
and removed
PR: out-of-date
The pull request has merge conflicts and can't be merged
labels
Nov 1, 2024
github-actions
bot
removed
the
PR: out-of-date
The pull request has merge conflicts and can't be merged
label
Nov 12, 2024
michaldudak
force-pushed
the
esm-build
branch
from
November 12, 2024 14:14
206c515
to
b791d4f
Compare
github-actions
bot
added
the
PR: out-of-date
The pull request has merge conflicts and can't be merged
label
Nov 14, 2024
Superseded by #821 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
core
Infrastructure work going on behind the scenes
PR: out-of-date
The pull request has merge conflicts and can't be merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Builds "true" ES modules alongside CommonJS output.
Summary of changes
/build/esm
/build/cjs
exports
field was added to the packagetypesVersion
field was added to package.json for compatibility with older tsconfig settingsmodule: "nodenext"
, the other one withmodule: "esnext"
.Type definitions
To verify if different methods of module resolution in TypeScript can resolve the exported types, the Are The Types Wrong (ATTW) tool was used. Its reports led to building the type definitions per build output (to avoid errors like False CJS and False ESM.
Another reported issue was the inability to resolve types under the
node10
module resolution when theexports
field is used. While we don't support Node 10, Typescript uses this resolution strategy by default (see https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/NoResolution.md#false-positive-unsupported-file-extension).To work around this, I introduced the
typesVersions
field in package.json, as described in https://github.com/andrewbranch/example-subpath-exports-ts-compat/tree/main/examples/node_modules/types-versions-wildcards.Testing
I created a repo to test the package with different bundlers and plain Node.js: https://github.com/michaldudak/base-ui-bundler-tests. There is an issue with running a Node.js app in ESM mode due to Base UI dependency on @mui/utils. The utils package does not currently conform to the ESM spec and cannot be used without a bundler this way.
As we're planning to move away from it and define our utilities locally, this won't be a problem for long.
This is built on top of #812