jest not working with absolute paths, how to fix in nestjs app

36 Views Asked by At

Whenever i run the unit or e2e tests i get the error:

Cannot find module 'src/users/entities/user.entity' from '../src/projects/entities/project.entity.ts'

from the test, because i'm using absolute paths in some files. Whenever I change these to relative paths in the code i get the error:

Error: Cannot find module '../../../src/users/entities/user.entity' nest_backend | Require stack: nest_backend | - /usr/src/app/dist/projects/entities/project.entity.js

from the backend.

I've tried applying the following in the jest configuration:

"moduleNameMapper": {
      "^src/(.*)$":"<rootDir>/$1"
    }

This doesn't fix my issues. Any help would be greatly appreciated.

0

There are 0 best solutions below