I have a typescript project and I setup aliases in ts.config.json
{
"compilerOptions": {
"paths": {
"@pkg/*": ["./packages/*"],
},
}
}
in my ts files I can shorten my import paths
// example.ts
import {someThing} from '@pkg/mypackage'
it works fine with tsc
and vscode can recognize the alias path correctly, but when I run npm t
which runs jest
it fails
Cannot find module '@pkg/mypackage' from 'example.ts'
jest.config.js
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
transform: {
"^.+\\.tsx?$": "ts-jest",
},
};
I added this to my package.json file
"jest": {
"moduleNameMapper": {
"@pkg/(.*)": "<rootDir>/packages/$1"
}
}
I managed to use pathsToModuleNameMapper
, but I had this issue
https://github.com/kulshekhar/ts-jest/issues/2709