Skip to content
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

Add ESM build #141

Merged
merged 4 commits into from
Mar 8, 2024
Merged

Add ESM build #141

merged 4 commits into from
Mar 8, 2024

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Mar 8, 2024

This package uses a default export, which gets transpiled to exports.default = SafeEventEmitter; by TypeScript. Importing this in an ESM environment does not work however:

// test.mjs
import SafeEventEmitter from '@metamask/safe-event-emitter';

// Logs: `{ default: SafeEventEmitter }`, instead of the expected `SafeEventEmitter`.
console.log(SafeEventEmitter);

Ideally we standardise this package to match the module template, but as a simple solution for now I've added a separate TypeScript config which outputs an ESM version instead. After this change, the console.log above logs the expected value.

@Mrtenz Mrtenz requested a review from a team as a code owner March 8, 2024 10:21
set -x
fi

for file in dist/esm/*.js; do
Copy link
Member

Choose a reason for hiding this comment

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

Can we not configure TypeScript to do this? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't look like it. There is an outFile setting but it doesn't work for ESM.

package.json Outdated Show resolved Hide resolved
@Mrtenz Mrtenz merged commit 95276c8 into main Mar 8, 2024
8 checks passed
@Mrtenz Mrtenz deleted the mrtenz/esm branch March 8, 2024 10:31
@Mrtenz Mrtenz mentioned this pull request Mar 9, 2024
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.

2 participants