Code Monkey home page Code Monkey logo

Comments (10)

LoganTann avatar LoganTann commented on August 16, 2024

Related: #1115

from ts-jest.

LoganTann avatar LoganTann commented on August 16, 2024

Found a workaround, suggested by the warning message when you disable "allowJs" :

  • Remove "compilerOptions.allowJs": true in your tsconfig file
  • Edit the transform regex to select only typescript files with ts-jest :
'transform': {
    '^.+\\.ts$': 'ts-jest', // << selects only ts. It was previously '^.+\\.(j|t)s$'
},

This is still an issue. This needs to be documented, as I had this issue since at least january and I had to investigate since I cleared my jest cache.

from ts-jest.

ahnpnl avatar ahnpnl commented on August 16, 2024

A bit background for this issue: ts-jest internally uses TypeScript compiler API to transform ts/js file into js file.

In general, setting allowJs to true is necessary if one wants the TypeScript compiler API to load and process JavaScript files in addition to TypeScript files when transforming files. This leads to the result that more files are loaded into memory which can blow up the machine.

Currently there are 2 workarounds:

With the release of typescript 5.5, now we can actually use other transpilers like esbuild or swc to process js files + opt in type checking from new v5.5 API

from ts-jest.

LoganTann avatar LoganTann commented on August 16, 2024

Good to know, thanks for the answer @ahnpnl ! Isolated modules did not solve the issue for me, but removing js files from ts-jest fixed it.

I just created another issue here : thisismydesign/nestjs-starter#468
It is very likely the previous developer in my project took the ts-config file in this template repo.

from ts-jest.

ahnpnl avatar ahnpnl commented on August 16, 2024

What is the issue with isolatedModules that you had? It supposed to be faster with true value (this is not tsconfig option btw, the name is confusing and we will rename it)

from ts-jest.

LoganTann avatar LoganTann commented on August 16, 2024

The reproduction repo has the isolatedModules set to true and my measurements takes account of this.

https://github.com/LoganTann/tsjest-performance-issue-reproduction/blob/main/jest.config.js

from ts-jest.

LoganTann avatar LoganTann commented on August 16, 2024

But the slowness is only due to js files being included in the transformer regex. isolatedModules does not seems to have any issue.

from ts-jest.

ahnpnl avatar ahnpnl commented on August 16, 2024

I see. Yes in this case Jest will give both js and ts to ts-jest to transform which explained the issue.

Theoretically if using fast transpiler like swc, it should be better. However, the recommendation is still only transform what is needed.

from ts-jest.

LoganTann avatar LoganTann commented on August 16, 2024

The recommendation is still only transform what is needed.

For sure ! In fact, to solve this issue, only a simple warning in the documentation would be required. We cannot do much to solve this, as in order to get this behavior, you need a configuration that is not recommended.

from ts-jest.

ahnpnl avatar ahnpnl commented on August 16, 2024

I agree, I will update documentation to have a note about this. Thanks for the suggestion!

from ts-jest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.