kulshekhar / ts-jest

A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
https://kulshekhar.github.io/ts-jest
MIT License
6.97k stars 454 forks source link

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

Closed EphraimB closed 4 months ago

EphraimB commented 1 year ago

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
BinToss commented 1 year ago

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.

ckrauterlovescoffee commented 6 months ago

Any updates on this?

ahnpnl commented 4 months ago

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

EphraimB commented 4 months ago

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

ahnpnl commented 4 months ago

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