ts-jest and monorepo baseUrl module resolution not working

18 Views Asked by At

I'm moving my project to monorepo using npm workspaces, and I'm having problems with configuration jest and ts-jest, my client side has a "baseUrl" option of "./src" in the tsconfig, and I can't seem to make ts-jest being able to import modules based on it, I really tried all of the options of modulePaths and moduleDirectories like they suggest in the troubleshooting and the docs,please let me know if you see anything I'm missing jest.config.js:

/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
    verbose: true,
    projects: [
        {
            preset: "ts-jest",
            testEnvironment: "node",
            displayName: "client",
            roots: ["<rootDir>/client/src"],
            moduleDirectories: [
                "./",
                "./client",
                "./client/node_modules",
                "./client/src",
                "./node_modules",
                "/home/user/code/monorepo/",
                "/home/user/code/monorepo/client/",
                "/home/user/code/monorepo/client/src",
                "<rootDir>/client",
                "<rootDir>/client/node_modules",
                "<rootDir>/client/src",
                "<rootDir>/node_modules",
                "client",
                "client/node_modules",
                "client/src",
                "node_modules",
            ],
            modulePaths: [
                "./",
                "./client",
                "./client/src",
                "/home/user/code/monorepo/",
                "/home/user/code/monorepo/client/",
                "/home/user/code/monorepo/client/src",
                "<rootDir>/",
                "<rootDir>/client",
                "<rootDir>/client/src",
                "client/src",
                "src"
            ],
            testMatch: [
                "<rootDir>/client/**/*.spec.ts",
                "<rootDir>/client/**/*.spec.tsx",
                "<rootDir>/client/**/*.test.ts",
                "<rootDir>/client/**/*.test.tsx"
            ]
        },
        {
            preset: "ts-jest",
            testEnvironment: "node",
            setupFiles: ["dotenv/config"],
            displayName: "server",
            roots: ["<rootDir>/server/src/"]
        }
    ]
};

as you can see I really put of all the options I could think of as the paths, from absolute to relative to relative to <rootDir>, but still getting Cannot find module 'app' or its corresponding type declarations. when importing import { app } from "app".

Would love any help!

0

There are 0 best solutions below