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

[Bug]: customConditions are not reset in fixupCompilerOptionsForModuleKind #4620

Open
Knagis opened this issue Nov 5, 2024 · 1 comment
Open

Comments

@Knagis
Copy link

Knagis commented Nov 5, 2024

Version

29.2.5

Steps to reproduce

use a tsconfig with

        "module": "preserve",
        "moduleResolution": "bundler",
        "customConditions": [
            "node",
        ],

Expected behavior

ts-jest transpiles .ts files

Actual behavior

  ● Test suite failed to run

    error TS5098: Option 'customConditions' can only be used when 'moduleResolution' is set to 'node16', 'nodenext', or 'bundler'.

Debug log

Additional context

https://github.com/kulshekhar/ts-jest/blob/main/src/legacy/compiler/ts-compiler.ts#L155 sets moduleResolution: "node" but it doesn't reset customConditions which are not supported with the new moduleResolution value. Adding customConditions: undefined works well.

Environment

System:
    OS: Windows 10 10.0.26100
    CPU: (16) x64 Intel(R) Core(TM) i7
  Binaries:
    Node: 22.11.0 - ~\AppData\Local\nvs\default\node.EXE
    Yarn: 4.1.1 - ~\AppData\Local\nvs\default\yarn.CMD
    npm: 10.9.0 - ~\AppData\Local\nvs\default\npm.CMD
  npmPackages:
    jest: 29.7.0 => 29.7.0
@Knagis
Copy link
Author

Knagis commented Nov 5, 2024

my patch for this locally:

diff --git a/dist/legacy/compiler/ts-compiler.js b/dist/legacy/compiler/ts-compiler.js
index 5198f8f1c395162d6ef02fa4297206a492b9bcbf..5cb00bfb629dfe01482028a2e9fe3546a032157b 100644
--- a/dist/legacy/compiler/ts-compiler.js
+++ b/dist/legacy/compiler/ts-compiler.js
@@ -116,7 +116,8 @@ var TsCompiler = /** @class */ (function () {
         var _a, _b;
         var moduleResolution = (_a = this._ts.ModuleResolutionKind.Node10) !== null && _a !== void 0 ? _a : this._ts.ModuleResolutionKind.NodeJs;
         if (!isEsm) {
-            return __assign(__assign({}, compilerOptions), { module: this._ts.ModuleKind.CommonJS, moduleResolution: moduleResolution });
+            // https://github.com/kulshekhar/ts-jest/issues/4620
+            return __assign(__assign({}, compilerOptions), { module: this._ts.ModuleKind.CommonJS, moduleResolution: moduleResolution, customConditions: undefined });
         }
         var moduleKind = (_b = compilerOptions.module) !== null && _b !== void 0 ? _b : this._ts.ModuleKind.ESNext;
         var esModuleInterop = compilerOptions.esModuleInterop;
@@ -124,7 +125,7 @@ var TsCompiler = /** @class */ (function () {
             esModuleInterop = true;
             moduleKind = this._ts.ModuleKind.ESNext;
         }
-        return __assign(__assign({}, compilerOptions), { module: moduleKind, esModuleInterop: esModuleInterop, moduleResolution: moduleResolution });
+        return __assign(__assign({}, compilerOptions), { module: moduleKind, esModuleInterop: esModuleInterop, moduleResolution: moduleResolution, customConditions: undefined });
     };
     TsCompiler.prototype.getCompiledOutput = function (fileContent, fileName, options) {
         var e_1, _a;

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