Can't run my Node.js Typescript project TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/App.ts

Remove "type": "module" from package.json


https://github.com/TypeStrong/ts-node/issues/935


If you don't want to remove "type": "module" (for example if you're using import statements in your .ts which allows the inference of types from modules), then you can use the following option in tsconfig.json:

{
  "compilerOptions": {
    "esModuleInterop": true,
  }
}

And then you can start the server with the config using ts-node.

Install:

npm install -g ts-node

Run:

ts-node my_server.ts

use

node --loader ts-node/esm ./my-script.ts

instead of

ts-node ./my-script.ts