Ts-jest: TypeError: (0 , _vm(...).compileFunction) is not a function

Created on 26 Jun 2020  ·  6Comments  ·  Source: kulshekhar/ts-jest

🐛 Bug Report

I have a super-simple typescript project I am trying to test. I setup jest following the readme instructions, and am only trying to test 1 typescript class. However, upon running npm t, I get:

> jest

 FAIL  src/debugout.spec.ts
  ● Test suite failed to run

    TypeError: (0 , _vm(...).compileFunction) is not a function

      at Runtime._execModule (node_modules/jest-runtime/build/index.js:1179:56)

Test Suites: 1 failed, 1 total

To Reproduce

Steps to reproduce the behavior:

  1. Clone this repo: https://github.com/inorganik/debugout.js/tree/typescript
  2. Make sure you ave the branch typescript checked out
  3. Run npm i then npm t

Expected behavior

Tests should run

Link to repo (highly encouraged)

https://github.com/inorganik/debugout.js

Debug log:

{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"26.1.1"},"message":"creating jest presets not handling JavaScript files","sequence":1,"time":"2020-06-26T16:10:03.257Z"}

envinfo

System:
    OS: macOS

Npm packages:
    jest: 26.1.0
    ts-jest: 26.1.1
    typescript: 3.9.5
    babel(optional):
Not An Issue

Most helpful comment

Updating to node v12 fixed it 👍

All 6 comments

I have cloned your repo on my Mac and I couldn't reproduce the issue.

image

I think there is a problem with your Mac. Did you run the test in a specific environment ?

A problem with my mac? Hmm.... I rolled jest and ts-jest back to v24 and it works, so it appears to be a problem introduced in a recent version of jest or ts-jest...

I don't believe the module type in tsconfig is the problem, as I have another repo with the same tsconfig and it tests just fine (also on v24 of both jest and ts-jest)

As you can above with WebStorm, I couldn't reproduce the issue. I saw this one somewhere in jest repo before. Not sure how to help in this case because I cannot reproduce the issue.

@ahnpnl which version of node are you at? I have v10.9.0

Oh I am using node 12, maybe you should use node 10.21.0 or higher. I think maybe jest doesn't support node 10.9

Updating to node v12 fixed it 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

remcohaszing picture remcohaszing  ·  4Comments

mikeyakymenko picture mikeyakymenko  ·  3Comments

bruk1977 picture bruk1977  ·  3Comments

Slessi picture Slessi  ·  3Comments

ahnpnl picture ahnpnl  ·  3Comments