Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
dandv opened this issue Aug 30, 2023 · 0 comments
Open

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

dandv opened this issue Aug 30, 2023 · 0 comments

Comments

@dandv
Copy link
Contributor

dandv commented Aug 30, 2023

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
@dandv dandv changed the title [Bug]: [Bug]: importing got v13 package causes Jest to fail to parse the file Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant