Skip to content

[Bug]: Warning: Failed to load the ES module: jest.config.cts #15897

@jlowcs

Description

@jlowcs

Version

30.2.0

Steps to reproduce

  1. create a simple repo with this package.json:
{
  "name": "test-jest",
  "version": "1.0.0",
  "devDependencies": {
    "@swc/jest": "^0.2.39",
    "@types/jest": "^30.0.0",
    "jest": "^30.2.0",
    "ts-node": "^10.9.2"
  }
}
  1. create a simple jest.config.cts file:
import type { Config } from 'jest';

const config: Config = {
	rootDir: __dirname,
	testMatch: ['<rootDir>/__tests__/**/*.test.(js|ts)'],
	transform: {
		'\\.(ts|js)$': '@swc/jest',
	},
};

// eslint-disable-next-line import/no-default-export
export default config;
  1. create a simple __tests__/foo.test.ts file:
describe('foo', () => {
  it('should pass this test', () => {
    expect(true).toBe(true);
  });
});
  1. run npx jest

Expected behavior

No warnings

Actual behavior

A warning appears in the console:

(node:81672) Warning: Failed to load the ES module: /(...)/jest.config.cts. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)

This does not prevent the tests from running properly. Afaik we should not need to add "type": "module" when naming the config file using the cts extension.

Note that the warning is absent when using the mts extension.

Additional context

No response

Environment

System:
    OS: macOS 15.7.1
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 24.11.0 - /Users/jeromelouis/.nvm/versions/node/v24.11.0/bin/node
    Yarn: 1.22.22 - /Users/jeromelouis/.nvm/versions/node/v22.11.0/bin/yarn
    npm: 11.6.1 - /Users/jeromelouis/.nvm/versions/node/v24.11.0/bin/npm
    pnpm: 10.14.0 - /Users/jeromelouis/.nvm/versions/node/v22.11.0/bin/pnpm
  npmPackages:
    jest: ^30.2.0 => 30.2.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions