Type error: Cannot find type definition file for '__mocks__'

817 Views Asked by At

This error began after switching to yarn workspaces and turbo for my set of nextjs projects. It seems to be related to jest, but I don't even have jest in any of my package.json files. I suspect it's related to a sub-dependency. I thought perhaps installing @types/jest would resolve this, but no luck. Looking for any suggestions on how to resolve, otherwise I'll post when I figure it out. The problem goes away when I remove the project from yarn workspaces.

Full error:

Type error: Cannot find type definition file for '__mocks__'.
  The file is in the program because:
    Entry point for implicit type library '__mocks__'

error Command failed with exit code 1.
1

There are 1 best solutions below

0
On

In my case I was able to resolve this error by explicitly listing the types I wanted included in tsconfig.json:

"compilerOptions": {
...
"types": [
      "node",
      "nodemailer",
      "react",
      "react-dom"
    ]
}

Solution was located here: https://github.com/microsoft/TypeScript/issues/27956

Very cryptic error and snuck into the code in an unexpected way for me (workspaces + turbo)