Mocha + TypeScript: Cannot use import statement outside a module

Had the same issue and almost gave up using Mocha with TypeScript (in our case Angular 9).

This is what helped me:

In tsconfig.json:

Replaced this:

"module": "esnext", 

with this:

"module": "commonjs",

Also here I found a working example of Mocha with TypeScript and used the tsconfig file from there to compare with mine:
https://medium.com/@RupaniChirag/writing-unit-tests-in-typescript-d4719b8a0a40

Leave a Comment

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