intellij-ideaimportpackage.jsonturborepo

IntelliJ won't automatically resolve internal packages in Turborepo


I have an internal package in my Turborepo setup. Here’s the package.json:

{
  "name": "@repo/shared-types",
  "version": "1.0.0",
  "main": "./index.js",
  "types": "./index.ts",
  "dependencies": {
    "typescript": "latest"
  }
}

I’ve added this package to the dependencies in my app's package.json:

"dependencies": {
   "@repo/shared-types": "*",
   ...
}

However, when I try to use things from this internal package, IntelliJ IDEA (2024.1.4) does not recognize it:

enter image description here

If I press Alt + Enter it does recognize the package, but it shows it only "below the line", therefore not resolving automatically:

enter image description here

What have I tried so far:

  1. File -> Invalidate caches
  2. Settings -> Editor -> General -> Auto Import -> Add unambiguous imports on the fly.
  3. Added "main": "index.js" to the package.json in my internal package

Any ideas?


Solution

  • Finally, after a few hours, I was able to solve it.

    If you add an empty tsconfig.json file (!!) in the root folder of the internal package, IntelliJ solves it automatically magically...

    resolved automatically

    I don't know if it's a bug in IntelliJ IDEA or has to do with Turborepo, but that sucks :(
    I hope it helps someone in the future.