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

fix(typescript): fix ESM build #1311

Merged
merged 1 commit into from
Oct 11, 2022
Merged

Conversation

lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented Oct 10, 2022

Do not use named imports from TypeScript

Rollup Plugin Name: typescript

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

Apparently, the TypeScript plugin does not work when imported as a Node ES module because it uses named imports to get properties from the typescript package. As this package is actually CommonJS, named exports do not work reliably and indeed throw. I added a test that shows this when used without the additional changes. The fix is to follow proper ESM semantics and only use the default export of the typescript package. Also, we cannot use __dirname in the generated code.

This is currently blocking the Rollup 3 release, for which proper Node ES module semantics will be crucial in plugins.

Do not use named imports from TypeScript
@lukastaegert lukastaegert merged commit dfd4de3 into master Oct 11, 2022
@lukastaegert lukastaegert deleted the fix-typescript-esm-build branch October 11, 2022 04:08
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