"formatDiagnostics is not a function" when I try to run my code with "ts-node index.ts" on Visual Studio Code

52 Views Asked by At
/usr/local/lib/node_modules/ts-node/src/index.ts:857
const diagnosticText = formatDiagnostics(diagnostics, diagnosticHost);
                     
TypeError: formatDiagnostics is not a function
at createTSError (/usr/local/lib/node_modules/ts-node/src/index.ts:857:28)
at reportTSError (/usr/local/lib/node_modules/ts-node/src/index.ts:863:19)
at createFromPreloadedConfig (/usr/local/lib/node_modules/ts-node/src/index.ts:874:36)
at phase4 (/usr/local/lib/node_modules/ts-node/src/bin.ts:543:44)
at bootstrap (/usr/local/lib/node_modules/ts-node/src/bin.ts:95:10)
at main (/usr/local/lib/node_modules/ts-node/src/bin.ts:55:10)
at Object.<anonymous> (/usr/local/lib/node_modules/ts-node/src/bin.ts:800:3)
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)

And I don't know how to fix it. Please, help me!!! My node version is 18.18, typescript version is 5.3.3, ts-node is 10.9.2

Or the issue depends on the versions of languages?

1

There are 1 best solutions below

1
ChocoNao On

As the similar issue states, your development environment seems to be broken in some way. Personally, I couldn't recreate this behavior with the matching stack:

❯ npx ts-node -vv
ts-node v10.9.2
node v18.18.2
compiler v5.3.3

The ts-node docs states that any error except TSError come from node and can be caused by bugs in your code or configuration.

Here are couple of possible solutions:

  • Try different version of node (you can use nvm), especially if you have multiple environments installed

  • Review your code and configuration files

  • Remove typescript and ts-node from node_modules directory and try:

    npm install ts-node --save-dev
    npm install -g typescript --save-dev