kulshekhar/ts-jest

[Bug]: importing `got` v13 package causes Jest to fail to parse the file

dandv opened this issue · 0 comments

Version

29.1.1

Steps to reproduce

  1. git clone https://github.com/dandv/got-jest && cd got-jest
  2. npm install
  3. node --loader ts-node/esm index.test.ts // correct error, ReferenceError: test is not defined, shows the ts-node setup works
  4. npm test

Expected behavior

I expect the test to pass.

Actual behavior

got-jest@1.0.0 test
jest

FAIL ./index.test.ts
● Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. [...]

Details:

/home/dan/prg/got-jest/node_modules/got/dist/source/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import create from './create.js';
                                                                                  ^^^^^^

SyntaxError: Cannot use import statement outside a module

> 1 | import got from 'got';
    | ^
  2 |
  3 | /* Commented out due to bogus error
  4 |  * error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
  at Object.<anonymous> (index.ts:1:1)
  at Object.<anonymous> (index.test.ts:1:1)

Debug log

ts-jest.log

Additional context

If I comment out the await got call from foo() and the console.log line that follows, the test passes, showing the ts-jest setup is correct.

I tried this configuration with babel-jest but it still failed.

Environment

System:
    OS: Linux 6.4 Fedora Linux 38 (KDE Plasma)
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
  Binaries:
    Node: 18.17.1 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.8.1 - /usr/local/bin/npm
    pnpm: 8.6.12 - ~/.local/bin/pnpm
  npmPackages:
    jest: ^29.6.4 => 29.6.4