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

Compile not outputing expected format #2121

Open
nonara opened this issue Jun 3, 2024 · 0 comments
Open

Compile not outputing expected format #2121

nonara opened this issue Jun 3, 2024 · 0 comments

Comments

@nonara
Copy link
Contributor

nonara commented Jun 3, 2024

Hey Andrew (@cspotcode)! Hope you're doing well.

I wanted to drop a quick heads up here on a potential issue. I'm not entirely sure if this is unexpected behaviour, so I'll just give the highlights and if it sounds like something is up, I can rewrite this with proper bug-report format & make a repro.

Backstory

We needed to make some changes to ts-patch to support the forthcoming typescript 5.5 release. They're doing some pretty interesting things to be able to support ESM. Not sure exactly what the status is on that as yet, but I know a lot of ground work has been laid.

After completing the changes, I ran into something that looks like it may be an issue on ts-node side, but again, I'm not certain.

Issue

We have been using ts-node to pre-compile typescript ESM transformers to JS, so we can use the esm library to require them. We did this via tsNodeInstance.compile(code, filePath).

This still works if I give it a file whose path is explicitly ".mts", but if it's ".ts", it seems to compile as cjs code.

Workaround & Other Details

I've confirmed and the config + compiler options specify both module and target as ESNext

As a workaround, I made it change the provided path to explicitly be "mts".

You can see the workaround here:

https://github.com/nonara/ts-patch/blob/master/projects/patch/src/plugin/esm-intercept.ts#L87-L94

Here is where we specify tsConfig:

https://github.com/nonara/ts-patch/blob/master/projects/patch/src/plugin/register-plugin.ts#L111-L120

I've confirmed it does register with those options via debugger.

If I'm just missing something, feel free to let me know! Otherwise, if you'd like to check into it, let me know, and I can make you a repro.

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

No branches or pull requests

1 participant