-
Notifications
You must be signed in to change notification settings - Fork 932
add esm entry points for node #5167
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
Conversation
|
Changeset File Check ✅
|
Binary Size ReportAffected SDKs
Test Logs |
Size Analysis Report |
"node": "./analytics/dist/index.cjs.js", | ||
"node": { | ||
"require": "./analytics/dist/index.cjs.js", | ||
"import": "./analytics/dist/index.esm.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file extension should be .mjs
, otherwise Node would fail to parse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, good catch! I fixed it in a different way by declaring "type": "module"
in the package.json
s, and changing the extension of cjs files from js to cjs, so they still work with require()
s. This way, I only need to generate 2 files per subpath, an esm.js file and a cjs file instead of 3(esm.js, esm.mjs and cjs.js).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it locally, and both import and require syntax work with this setup.
Addresses #5140