Before ask this question, I checked similar topics and tried typical solutions.
I know what the frequent cause is "module": "ESXXXX"
in TypeScript configuration.
In my case, I have error
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\IntelliJ IDEA\XXXXXX\node_modules\tsconfig-paths\src\__tests__\config-loader.test.ts
in both "module": "ESnext"
and "module": "CommonJS"
cases.
One of typical solution is usage of ts-node/esm. First, this feature is experimental. Next, it just replace one error with another:
(node:24788) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
× ERROR: CustomError: Cannot find module 'D:\IntelliJ IDEA\XXXXX\node_modules\tsconfig-paths\register' imported from D:\IntelliJ IDEA\XXXXX\node_modules\mocha\lib\nodejs\esm-utils.js
Versions
- mocha: 9.2.1
- ts-node: 10.7.0
Mocha config
extension:
- ts
spec: "**/*.test.ts"
require:
- ts-node/register
- tsconfig-paths/register
loader: ts-node/esm # Tried with and without