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

.cjs extension is supported, but not .cts in version 2 (rc) #25498

Closed
wellwelwel opened this issue Sep 7, 2024 · 4 comments · Fixed by #26558
Closed

.cjs extension is supported, but not .cts in version 2 (rc) #25498

wellwelwel opened this issue Sep 7, 2024 · 4 comments · Fixed by #26558
Assignees
Milestone

Comments

@wellwelwel
Copy link

wellwelwel commented Sep 7, 2024

Version: Deno 2.0.0-rc.1

I noticed that, in version 2, I can run .cjs files, but not .cts files. Using any version from 1.x.x onwards, including the latest (1.46.3), both runs work fine.

I'd like to understand it better:

Is it intentional to accept .cjs but not .cts (not an issue), should both not be supported or should both work as in previous major version?

The message error:

Expected a JavaScript or TypeScript module, but identified a Cts module. Importing these types of modules is currently not supported.
  • Perhaps "unrecognized" fits better than "not supported" for this report.
  • This error doesn't occur during import, but with the deno run command.

For a brief context, these tests are totally empty files, just to make sure that a test runner is properly targeting each file by extension according to how each runtime (Node.js, Bun and Deno) handles them.

Before v2 (1.46.3):

Screenshot 2024-09-06 at 21 10 12

After v2 (2.0.0-rc.1):

Screenshot 2024-09-06 at 21 17 14
Screenshot 2024-09-06 at 21 19 00

Minimal Reproduction

test.cts

console.log(123);
deno run test.cts

Output:

error: Expected a JavaScript or TypeScript module, but identified a Cts module. Importing these types of modules is currently not supported.
  Specifier: file:///***/test.cts

Being my first issue here, thanks for Deno 🦕💙

@wellwelwel wellwelwel changed the title .cjs imports are supported, but not .cts in version 2 (rc) .cjs extension is supported, but not .cts in version 2 (rc) Sep 7, 2024
@bartlomieju bartlomieju added this to the 2.0.0-rc.2 milestone Sep 8, 2024
@bartlomieju bartlomieju modified the milestones: 2.0.0-rc.2, 2.0.0-rc.3, 2.0.0 Sep 12, 2024
@bartlomieju bartlomieju modified the milestones: 2.0.0, 2.1.0 Sep 23, 2024
@wesbos
Copy link

wesbos commented Oct 24, 2024

hitting this as well in an app where 1 file must be a commonJS file due to some limitations on ESM module cache, but I'd also like for it to be TypeScript. No way around this right now?

@dsherret
Copy link
Member

Not at the moment. We put it off because the use of cts files seems low at the moment (https://github.com/search?type=code&q=path%3A*.cts), but we'd like to do it soon.

@wesbos
Copy link

wesbos commented Oct 24, 2024

Ah yeah, makes sense. I ended up just stripping the types from that file but it turns out I don't even need any of the weird cache stuff I'm doing in Node because of hmr in deno.

@dsherret
Copy link
Member

I have a draft PR here: #26558

image

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 a pull request may close this issue.

4 participants