Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
rafgraph opened this issue Oct 19, 2020 · 5 comments · Fixed by #10675
Closed

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

rafgraph opened this issue Oct 19, 2020 · 5 comments · Fixed by #10675

Comments

@rafgraph
Copy link

rafgraph commented Oct 19, 2020

🐛 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 
@rafgraph
Copy link
Author

@Gamote any thoughts on this? (PR for supporting jest.config.ts)

@Gamote
Copy link
Contributor

Gamote commented Oct 20, 2020

@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.

@rafgraph rafgraph changed the title TS config error: SyntaxError: Unexpected token 'export' TS jest.config.ts error: SyntaxError: Unexpected token 'export' Oct 20, 2020
@MikeyUchiha
Copy link

@Gamote I am also having the same issue on a brand new project. Thanks for looking into this!

image

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;

@SimenB
Copy link
Member

SimenB commented Oct 23, 2020

Out in 26.6.1

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants