knip
knip copied to clipboard
Module Resolution Issues Across Multiple Workspaces with TSConfig Paths
It seems that there are potential problems with complex monorepos with each workspace using tsconfig paths or baseurl. If workspace A imports from workspaces B and both workspaces use tsconfig paths, then knip will split the workspaces into 2 different principals. However, when Principal A analyzes workspace A, it will also analyze the imported file from workspace B. Unfortunately, it tries to analyze the file from workspace B using the config options from workspace A, so the bare imports that rely on paths or baseurl end up being reported as unlisted. Furthermore, because the resolution gets cached, even attempts to reanalyze the file as part of Workspace B doesn't fix the problem, so I don't think it can be solved reliably with knip config settings.
This behavior depends on the workspace ordering, so it doesn't reproduce in all circumstances. Some monorepos might just work from pure luck. However, I was able to create a simple repro here.