Using jest.config.ts and running jest I get the following error:
Error: Jest: Failed to parse the TypeScript config file /Users/rafael/dev/maintained/detect-it/jest.config.ts
SyntaxError: Unexpected token 'export'
I have TypeScript setup for es modules, but maybe there is something else I'm missing, tsconfig.json here. I installed ts-node and copied the jest.config.ts from the docs.
Create jest.config.ts:
import type {Config} from '@jest/types';
const config: Config.InitialOptions = {
verbose: true,
};
export default config;
Run npx jest
For jest.config.ts to parse and tests to run.
Trying to convert the jest config from js to ts in this repo branch:
https://github.com/rafgraph/detect-it/tree/jest-ts-config
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Binaries:
Node: 12.18.3 - ~/.n/bin/node
Yarn: 1.22.5 - ~/.n/bin/yarn
npm: 6.14.8 - ~/.n/bin/npm
npmPackages:
jest: ^26.6.0 => 26.6.0
@Gamote any thoughts on this? (PR for supporting jest.config.ts)
@rafgraph Hmm, looks like the tsconfig.json is interfering with the internal compiler's settings. I will have a look in detail later or tomorrow.
@Gamote I am also having the same issue on a brand new project. Thanks for looking into this!

import type { Config } from '@jest/types';
const config: Config.InitialOptions = {
moduleFileExtensions: ['ts', 'tsx', 'js'],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|js?|tsx?|ts?)$',
globals: {
NODE_ENV: 'test'
},
snapshotSerializers: ['enzyme-to-json/serializer'],
transform: {
'^.+\\.(j|t)sx?$': 'babel-jest'
},
coveragePathIgnorePatterns: [
'/node_modules/',
'jest.setup.ts',
'<rootDir>/configs/',
'jest.config.ts',
'.json',
'.snap'
],
setupFiles: ['<rootDir>/jest.setup.ts'],
coverageReporters: ['json', 'lcov', 'text', 'text-summary'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/mocks.ts',
'\\.(css|less|scss)$': '<rootDir>/__mocks__/mocks.ts'
}
};
export default config;
Out in 26.6.1