I have a quite new NestJS application. I\'m trying to run unit tests, but they keep failing due to \'cannot find module..\' when using absolute paths ("src/users/...")
I believe you are missing the rootDir
in your tsconfig.json
If you want to import { ... } from 'src/...
, the rootDir
needs to be equal to ./
.
Check this example:
{
"moduleFileExtensions": [
"ts",
"tsx",
"json",
"js"
],
"rootDir": "./",
"testRegex": ".spec.ts$",
"collectCoverageFrom": ["**/*.ts", "!**/node_modules/**"],
"coverageDirectory": "./coverage",
"coverageReporters": ["html", "text", "text-summary"],
"preset": "ts-jest",}
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./",
"baseUrl": "./",
"incremental": true
}