TypeStrong / ts-node

TypeScript execution and REPL for node.js
https://typestrong.org/ts-node
MIT License
12.75k stars 529 forks source link

tsconfig not found when extends scope with ts-node>10.0 and typescript@>=5.3.0-dev #2076

Closed bluelovers closed 7 months ago

bluelovers commented 9 months ago

Search Terms

not found tsconfig

Expected Behavior

no error like ts-node@10.0

Actual Behavior

    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
error TS6053: File '@bluelovers/tsconfig/esm/mapfile.json' not found.

    at createTSError (C:\Users\User\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:859:12)
    at reportTSError (C:\Users\User\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:863:19)
    at createFromPreloadedConfig (C:\Users\User\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:874:36)
    at phase4 (C:\Users\User\AppData\Roaming\npm\node_modules\ts-node\src\bin.ts:543:44)
    at bootstrap (C:\Users\User\AppData\Roaming\npm\node_modules\ts-node\src\bin.ts:95:10)
    at main (C:\Users\User\AppData\Roaming\npm\node_modules\ts-node\src\bin.ts:55:10)
    at Object.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\ts-node\src\bin-cwd.ts:5:5)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32) {
  diagnosticCodes: [ 6053 ]
}

Steps to reproduce the problem

global install typescript>=5.3.0-dev global/local install ts-node@>10.0

{
  "extends": "@bluelovers/tsconfig/esm/mapfile.json",
  "compilerOptions": {
    "disableReferencedProjectLoad": true,
    "importHelpers": true,
    "noPropertyAccessFromIndexSignature": false
  }
}

node_modules/ts-node/dist/configuration.js

 const resolvedExtendedConfigPath = tsInternals.getExtendsConfigPath(c.extends, {
                    fileExists,
                    readDirectory: ts.sys.readDirectory,
                    readFile,
                    useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
                    trace: tsTrace,
                }, bp, errors, ts.createCompilerDiagnostic);

Minimal reproduction

Specifications

bluelovers commented 9 months ago

https://github.com/TypeStrong/ts-node-repros/pull/35

dipunm commented 8 months ago

I have ran into this issue with the latest release of typescript@5.3.2 https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/

ts-node version: v10.9.1

Azerothian commented 8 months ago

5.3.2 just went live 8 hours ago and i got the similar error with extending @tsconfig/node18

TSError: ⨯ Unable to compile TypeScript:
error TS6053: File '@tsconfig/node18/tsconfig.json' not found.

    at createTSError (/home/dev/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/dev/node_modules/ts-node/src/index.ts:863:19)
    at createFromPreloadedConfig (/home/dev/node_modules/ts-node/src/index.ts:874:36)
    at create (/home/dev/node_modules/ts-node/src/index.ts:624:10)
    at Object.register (/home/dev/node_modules/ts-node/src/index.ts:591:15)
    at Object.<anonymous> (/home/dev/node_modules/ts-node/register/index.js:1:16)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12) {
  diagnosticCodes: [ 6053 ]
}

tsconfig.json

{
  "extends": "@tsconfig/node18/tsconfig.json",
  "compilerOptions": {
    "experimentalDecorators": true,
    "removeComments": false,
    "preserveConstEnums": true,
  },
  "include": ["src/**/*", ".jest", "__tests__", "__tests__/.jest/*", "__tests__/utils/*"],
  "exclude": ["node_modules", "old"],
  "ts-node": {
    "files": true
  },
}
edosrecki commented 8 months ago

I added reproduction with the latest 5.3.2 version of typescript: https://github.com/TypeStrong/ts-node-repros/pull/36

me4502 commented 8 months ago

This issue has also been reported to TypeScript it seems; https://github.com/microsoft/TypeScript/issues/56492

effektsvk commented 8 months ago

Hello, yes, that is the same issue. I debugged the issue and posted the culprit there: https://github.com/microsoft/TypeScript/issues/56492#issuecomment-1823213512

edosrecki commented 8 months ago

I guess we need to accommodate for this internal API change by providing different arguments based on the Typescript version being used.

I started the work here: https://github.com/TypeStrong/ts-node/pull/2091

patozavala commented 7 months ago

Hi all,

I modified the tsconfig.json's extends path as follows: before: "extends": "ts-node/node16/tsconfig.json", after: "extends": "./node_modules/@tsconfig/node16/tsconfig.json",

In my case I am using:

 "ts-node": "10.9.1",
 "typescript": "5.3.2"
 "pm2": "^5.3.0",

And it works

effektsvk commented 7 months ago

@patozavala yes, I can confirm this workaround, I found it as well but forgot to post 😅 sorry

karlhorky commented 7 months ago

This also affects Jest with TypeScript configuration files, because Jest uses ts-node by default

karlhorky commented 7 months ago

Workaround (apply patch before PR merged)

To apply the patch directly before #2091 is merged (eg. using patch-package or pnpm patch):

node_modules/ts-node/dist/ts-internals.js

    function getExtendsConfigPath(extendedConfig, host, basePath, errors, createDiagnostic) {
        extendedConfig = (0, util_1.normalizeSlashes)(extendedConfig);
        if (isRootedDiskPath(extendedConfig) ||
            startsWith(extendedConfig, './') ||
            startsWith(extendedConfig, '../')) {
            let extendedConfigPath = getNormalizedAbsolutePath(extendedConfig, basePath);
            if (!host.fileExists(extendedConfigPath) &&
                !endsWith(extendedConfigPath, ts.Extension.Json)) {
                extendedConfigPath = `${extendedConfigPath}.json`;
                if (!host.fileExists(extendedConfigPath)) {
                    errors.push(createDiagnostic(ts.Diagnostics.File_0_not_found, extendedConfig));
                    return undefined;
                }
            }
            return extendedConfigPath;
        }
        // If the path isn't a rooted or relative path, resolve like a module
        const resolved = ts.nodeModuleNameResolver(extendedConfig, combinePaths(basePath, 'tsconfig.json'), { moduleResolution: ts.ModuleResolutionKind.NodeJs }, host,
        /*cache*/ undefined,
        /*projectRefs*/ undefined,
+        /*conditionsOrIsConfigLookup*/ undefined,
        /*lookupConfig*/ true);
        if (resolved.resolvedModule) {
            return resolved.resolvedModule.resolvedFileName;
        }
        errors.push(createDiagnostic(ts.Diagnostics.File_0_not_found, extendedConfig));
        return undefined;
    }
    return { getExtendsConfigPath };
}
adrian-gierakowski commented 7 months ago

Could a new 11.beta release be cut with this fix included please? Thanks!

AlessandroVol23 commented 2 months ago

This also affects Jest with TypeScript configuration files, because Jest uses ts-node by default

I face this issue with jest right now. Is there any workaround or fix already available? I'm on the latest (29.7.0) jest version

adrian-gierakowski commented 2 months ago

for people using yarn (berry) you can use https://www.npmjs.com/package/ts-node/v/11.0.0-beta.1 with the following patch:


diff --git a/dist/ts-internals.js b/dist/ts-internals.js
index 2b303c90edf91dcc3bf9988586570b9988f05187..99ea07b39a0fb1801a3bdc7ee6234b5d0f432c3f 100644
--- a/dist/ts-internals.js
+++ b/dist/ts-internals.js
@@ -34,9 +34,10 @@ function createTsInternalsUncached(_ts) {
             return extendedConfigPath;
         }
         // If the path isn't a rooted or relative path, resolve like a module
-        const resolved = ts.nodeModuleNameResolver(extendedConfig, combinePaths(basePath, 'tsconfig.json'), { moduleResolution: ts.ModuleResolutionKind.NodeJs }, host, 
-        /*cache*/ undefined, 
-        /*projectRefs*/ undefined, 
+        const resolved = ts.nodeModuleNameResolver(extendedConfig, combinePaths(basePath, 'tsconfig.json'), { moduleResolution: ts.ModuleResolutionKind.NodeJs }, host,
+        /*cache*/ undefined,
+        /*projectRefs*/ undefined,
+        /*conditionsOrIsConfigLookup*/ undefined,
         /*lookupConfig*/ true);
         if (resolved.resolvedModule) {
             return resolved.resolvedModule.resolvedFileName;
``
sethidden commented 2 months ago

This was fixed for me by updating from ts-node 10.9.1 to 10.9.2 - just remove ts-node from your lockfile and run install again. I'm writing so people aren't confused - 10.9.2 was released after 11.0.0 beta, so this is probably why the above poster is patching.

AlessandroVol23 commented 2 months ago

I got it fixed as well by overriding all peer dependencies and update ts-node to 10.9.2