Skip to content

Add ESM build#141

Merged
Mrtenz merged 4 commits intomainfrom
mrtenz/esm
Mar 8, 2024
Merged

Add ESM build#141
Mrtenz merged 4 commits intomainfrom
mrtenz/esm

Conversation

@Mrtenz
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@Mrtenz Mrtenz merged commit 95276c8 into main Mar 8, 2024
@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