question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

🐛 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 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Oct 23, 2020

Out in 26.6.1

1reaction
MikeyUchihacommented, Oct 21, 2020

@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;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected token export, when import not compiled libraries ...
FAIL src/index.test.js ○ Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a...
Read more >
Jest gives an error: "SyntaxError: Unexpected token export"
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >
TypeScript Jest: Unexpected Token Export - Reddit
I'm trying to run unit tests for a TypeScript project which uses another TypeScript project I've created as a dependency. However, despite ...
Read more >
jest syntaxerror: unexpected token export - You.com | The AI ...
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >
SyntaxError: Unexpected token export - velog
Actual Code Solution · 1) .babelrc.json · transform-es2015-modules-commonjs · 2) jest.config.ts · ts-jest · babel-jest · 3) package.json.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found