deno
deno copied to clipboard
`.cjs` extension is supported, but not `.cts` in version 2 (rc)
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 runcommand.
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):
After v2 (2.0.0-rc.1):
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 🦕💙
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?
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.
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.
I have a draft PR here: https://github.com/denoland/deno/pull/26558