Include ".ts" in `extensionsToTreatAsEsm` for TypeScript projects with "type": "module"
🚀 Feature Proposal
Include ".ts" in the default values of extensionsToTreatAsEsm for TypeScript projects with "type": "module".
Motivation
The TypeScript compiler treats .ts files as their would-be .js counterparts for interactions relating to the TS-to-JS transpilation effort. The purpose of this behavior is to better represent the runtime shape and structure of the output.
The underlying behavior of requiring ".ts" in extensionsToTreatAsEsm breaks this abstraction, at least in terms of its name. It's not TypeScript that should be treated as ES Modules but rather the corresponding JavaScript it represents. Requiring manual configuration on the part of the user pushes this misunderstanding onto others.
Not even the TypeScript compiler allows TypeScript files to be treated as ES Modules:
$ tsc --build
src/index.ts:1:25 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing './version.js' instead.
1 import { version } from "./version.ts";
~~~~~~~~~~~~~~
Note that, if the import syntax were changed to that of CommonJS (in other words, require), there would be no error.
In leu of requesting a deeper change in the way Jest manages anything really internal to stamp out this break in abstraction entirely, the easiest solution to alleviate this issue is to include ".ts" to extensionsToTreatAsEsm by default.
Pitch
- Nearly every TypeScript project that uses Jest would be able to take advantage of this change immediately.
- There would be no requirement for new users to create a configuration file to specifically enable this behavior.
- Jest would work with no configuration whatsoever for TypeScript projects.
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
Not stale
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.