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

Typescript Program is undefined when ts-jest isolatedModule is true #2972

Open
2 of 4 tasks
edeesis opened this issue Jun 7, 2024 · 0 comments
Open
2 of 4 tasks

Typescript Program is undefined when ts-jest isolatedModule is true #2972

edeesis opened this issue Jun 7, 2024 · 0 comments

Comments

@edeesis
Copy link

edeesis commented Jun 7, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

ts-jest has a isolatedModules option, which, when set to true, makes the program undefined, from this PR.

This causes the ModelClassVisitor and ControllerClassVisitor to immediately fail to retrieve the type checker.

 ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'getTypeChecker')

 at ModelClassVisitor.visit (node_modules/@nestjs/swagger/dist/plugin/visitors/model-class.visitor.js:35:37)
      at node_modules/@nestjs/swagger/dist/plugin/compiler-plugin.js:15:42
      at transformSourceFileOrBundle (node_modules/typescript/lib/typescript.js:89058:51)
      at transformation (node_modules/typescript/lib/typescript.js:112184:16)
      at transformRoot (node_modules/typescript/lib/typescript.js:112207:73)
      at transformNodes (node_modules/typescript/lib/typescript.js:112192:72)
      at emitJsFileOrBundle (node_modules/typescript/lib/typescript.js:112779:26)
      at emitSourceFileOrBundle (node_modules/typescript/lib/typescript.js:112714:7)
      at forEachEmittedFile (node_modules/typescript/lib/typescript.js:112468:26)
      at emitFiles (node_modules/typescript/lib/typescript.js:112688:5)
      at emitWorker (node_modules/typescript/lib/typescript.js:120187:26)
      at node_modules/typescript/lib/typescript.js:120172:53
      at runWithCancellationToken (node_modules/typescript/lib/typescript.js:120261:16)
      at Object.emit (node_modules/typescript/lib/typescript.js:120172:22)
      at Object.transpileModule (node_modules/typescript/lib/typescript.js:135707:13)
      at TsCompiler._transpileOutput (node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:211:25)
      at TsCompiler.getCompiledOutput (node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:201:31)
      at TsJestCompiler.getCompiledOutput (node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js:14:39)
      at TsJestTransformer.exports.TsJestTransformer.TsJestTransformer.processWithTs (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:259:37)
      at TsJestTransformer.exports.TsJestTransformer.TsJestTransformer.process (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:188:24)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:545:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:726:19)
[... source code redacted]

Minimum reproduction code

https://github.com/edeesis/swagger-reproduce

Steps to reproduce

  1. npm install
  2. npm run test:e2e

Expected behavior

The compiler plugin should still work if isolatedModules is set to true, though I'm not sure how this would be done with how tightly coupled the compiler plugin is with the TS Program.

You may be able to instantiate a ts.Program object in the compiler plugin, not sure how that would work.

Package version

7.1.31

NestJS version

10.3.3

Node.js version

20.10.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

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