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

Support ESM typescript modules #46

Open
achingbrain opened this issue Jun 14, 2022 · 0 comments
Open

Support ESM typescript modules #46

achingbrain opened this issue Jun 14, 2022 · 0 comments

Comments

@achingbrain
Copy link

achingbrain commented Jun 14, 2022

If your tsconfig.json has "module": "ES2020" or later (e.g you are outputting ESM and not CJS), TypeScript doesn't rewrite import './foo' to import './foo.js' in the transpiled output - instead you have to use import './foo.js' in your .ts file.

This module then breaks because it (quite reasonably) detects './foo.js' as a dependency which of course doesn't exist.

I've hacked round it by replacing the file extension here and here but it doesn't take into account if ./foo.js does actually exist and that's what you meant to import. I don't know the AST well enough to make that change, but a simple fs.existsSync should be enough?

Another workaround is to run the dep checker over the transpiled output instead of the ts source, but then you lose any import type declarations, so it's not ideal.

Refs: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#type-in-package-json-and-new-extensions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants