deno icon indicating copy to clipboard operation
deno copied to clipboard

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

Open wellwelwel opened this issue 1 year ago • 4 comments

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 avatar Sep 07 '24 00:09 wellwelwel

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?

wesbos avatar Oct 24 '24 16:10 wesbos

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.

dsherret avatar Oct 24 '24 17:10 dsherret

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.

wesbos avatar Oct 24 '24 18:10 wesbos

I have a draft PR here: https://github.com/denoland/deno/pull/26558

image

dsherret avatar Oct 25 '24 23:10 dsherret