Skip to content

TS jest.config.ts error: SyntaxError: Unexpected token 'export' #10652

@rafgraph

Description

@rafgraph

🐛 Bug Report

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.

To Reproduce

Create jest.config.ts:

import type {Config} from '@jest/types';

const config: Config.InitialOptions = {
  verbose: true,
};
export default config;

Run npx jest

Expected behavior

For jest.config.ts to parse and tests to run.

Link to repl or repo (highly encouraged)

Trying to convert the jest config from js to ts in this repo branch:
https://github.com/rafgraph/detect-it/tree/jest-ts-config

envinfo

  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 

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