#4013·ts-jest

[Feature]: reconsider how to handle file extensions in import path specifiers

Author: thw0rtedCreated Feb 2, 2023Updated Apr 1, 2026
Labels:rocket: Feature Request

Feature Proposal

The examples shipped with this project should include both tests and code-under-test which imports from relative paths using a file extension. Any additional configuration required to support this should work out of the box, without additional steps required by the user.

Motivation

TypeScript written to run in a Node environment is changing. Since the introduction of moduleResolution: 'nodeNext', users are being encouraged to write relative import path specifiers with an explicit file extension, which must be .js, regardless of whether the file being imported is written in JS or TS.

If you have a whole afternoon to kill, go ahead and read https://github.com/microsoft/TypeScript/issues/50152, but otherwise take my word for it: this will become more common over time. This convention is not supported out of the box today, and it should be.

Jest does not officially support testing TS, so they aren't going to take responsibility for making this work. ts-jest should at least include examples of using this convention, and should either make it work without configuration, or specify which additional steps are required in the documentation.

Example

typescript
// @filename foo.ts
export const foo = "hello";

// @filename foo.spec.ts
import { foo } from './foo.js';

it('should exist', () => {
  expect(foo).toBeDefined();
});

ETA: previous discussion was here https://github.com/kulshekhar/ts-jest/issues/1057