Remove "type": "module"
from package.json
https://github.com/TypeStrong/ts-node/issues/935
https://github.com/TypeStrong/ts-node/issues/1007#issuecomment-1163471306
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-esm my_server.ts