Use yarn workspaces and typescript's project references to reference another package subdirectory Use yarn workspaces and typescript's project references to reference another package subdirectory typescript typescript

Use yarn workspaces and typescript's project references to reference another package subdirectory


Moving to the root at builds works and avoids tooling issues but as mentioned it complicates building, especially for sharing in workspaces. The "exports" field node 14 is an important change that should ultimately make supporting subdirectory exports easier but for now it only solves part of the problem since other tooling doesn't seem to respect the field yet. The specific error mentioned would still exist with typescript's path resolution that can be resolved using the "baseUrl" and "paths" options in your tsconfig.json file at the root and then using "extends" to share that config. Unfortunately if the lib ends up getting used by something built with webpack and you're using v4 you'll need to configure custom path resolution step because webpack doesn't support the "exports" field. It does appear to be part of webpack 5 if you can use that. So, if you're not publishing your lib outside of the mono repo then this is solvable without moving everything to the root with newer tools and some configuration work.


Update on this: With Nodejs 14, you can specify subpath exports in your package.json.

https://nodejs.org/api/esm.html#esm_subpath_exports

I haven't tested that personally, but it looks like it can fix this issue by using

"exports": {  ".": "./lib"}