Ts-node : SyntaxError: Cannot use import statement outside a module

After a lot of searching, I found this solution works perfect:

https://github.com/TypeStrong/ts-node/issues/922#issuecomment-673155000

Just add a "ts-node" block to your tsconfig.json file as below:

{
  "ts-node": {
    "compilerOptions": {
      "module": "commonjs"
    }
  },
  "compilerOptions": {
    "module": "esnext"
  }
}

And it has been documented in the ts-node official page “Via tsconfig.json” part.

This saved hours of my life.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)