Skip to content

fix(typescript): fix ESM build - #1311

Merged
lukastaegert merged 1 commit into
masterfrom
fix-typescript-esm-build
Oct 11, 2022
Merged

lukastaegert merged 1 commit into
masterfrom
fix-typescript-esm-build

Conversation

@lukastaegert

@lukastaegert lukastaegert commented Oct 10, 2022 •

Copy link
Copy Markdown
Member

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