'mocha ts-node cannot find d.ts modules

I am trying to add my typescript tsconfig.json to run together with mocha, ts-node and tsconfig-paths.

I want to use *.d.ts files in my project tests. Running my code works with *.d.ts files, however for my tests I am getting the following error:

Error: Cannot find module '@core/types/utilty'

for this import statement:

import { TimeUnit } from '@core/types/utilty';

I've checked several online related discussions and none helped solve this error:

Help! My Types Are Missing! (tsc vs ts-node disparity)

mocha and ts-node cannot find local .d.ts file

Can anyone assist? My run command:

mocha --config config/.mocharc.js **/*.test.ts

Project structure is:

|--package.json
|--tsconfig.json
|--config
|  |--.mocharc.js
|--src
|  |--...
|  |--...
|--test
|  |--tsconfig.tests.json
|  |--...
|--...

My .mocharc.js is as follows:

process.env.TS_NODE_PROJECT = `${TestsFolder}/tsconfig.tests.json`;
const isCI = !!process.env.CI

module.exports = {
    spec,
    require: [
        'ts-node/register',
        'tsconfig-paths/register',
        ...
    ],
    timeout: 0
}

tsconfig.js:

{
  "compilerOptions": {
    "target": "ES2018",
    "lib": ["esnext", "dom.iterable", "dom"],
    "baseUrl": ".",
    "paths": {
      "@core/*": [ "src/core/*" ],
    },
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "module": "esnext",
    "moduleResolution": "node",
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": ["src"]
}

tsconfig.tests.json

{
  "extends": "../tsconfig.json",
  "ts-node": {
    "transpileOnly": true,
    "files": true,
    "compilerOptions": {
      "module": "commonjs"
    }
  },
  "compilerOptions": {
    "baseUrl": "../",
  },
  "include": [
    "../src/**/*",
    "../test/**/*"
  ]
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source