ts-jest icon indicating copy to clipboard operation
ts-jest copied to clipboard

[Bug]: import.meta.url doesn't work

Open EphraimB opened this issue 1 year ago • 2 comments

Version

29.1.1

Steps to reproduce

  1. Clone at https://github.com/EphraimB/budgeting and use the ts-jest branch
  2. npm install
  3. npm run test -- app.test.ts
  4. Test fails without an error message

Expected behavior

I expect the test to pass

Actual behavior

Test fails without an error message

Debug log

ts-jest.log

Additional context

The production code runs. It's just the test that passes.

Environment

System:
    OS: macOS 13.4.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
  Binaries:
    Node: 18.13.0 - /usr/local/bin/node
    npm: 8.19.3 - /usr/local/bin/npm
  npmPackages:
    jest: ^29.6.1 => 29.6.1

EphraimB avatar Jul 07 '23 18:07 EphraimB

Deciphered from your log:

app.ts: 21:46 - error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

21 const __dirname = fileURLToPath(new URL('.', import.meta.url));
                                                ~~~~~~~~~~~
app.ts:31:1 - 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.

31 await initializeBree();
   ~~~~~

I've noticed TypeScript errors aren't being formatted and printed to the console when run by ts-jest.

BinToss avatar Oct 01 '23 14:10 BinToss

Any updates on this?

ckrauterlovescoffee avatar Apr 25 '24 21:04 ckrauterlovescoffee

Hi @EphraimB @ckrauterlovescoffee do you still experience the issue? Are you running Jest in ESM mode?

ahnpnl avatar Jul 10 '24 00:07 ahnpnl

I'm migrating my code away from express to NestJS so this issue doesn't affect me anymore.

EphraimB avatar Jul 10 '24 00:07 EphraimB

i will close this issue for now. If anyone still experiences the issue with latest version, pls feel free to open another issue.

ahnpnl avatar Jul 11 '24 12:07 ahnpnl