Here is the case. I am using Nrwl NX Monorepo. I have 2 libraries: lib-a and lib-b; both are publishable libraries created via NX.
Now I create a MyClass.ts in lib-a. Naturally under paths in workspace/tsconfig.json > paths NX creates an alias to this lib-a ("@workspace/lib-a": ["libs/lib-a/src/index.ts"]).
So far so good. Now we can use this class anywhere within the workspace/monorepo by importing it via import { MyClass } from '@workspace/lib-a';
Unfortunately we can not build lib-b which is importing MyClass. When we try to do it we get the bellow error. So question is how can we build lib-b ?
PS: It seems strange that NX monorepo actually don't support such a common scenario linking 2 publishable libs.
"error TS6059: File "d:/workspace/libs/lib-a/src/index.ts" is not under 'rootDir' "d:\workspace\libs\lib-b\src" rootDir is expected to contain all source files"
Try adding
"paths": { "@workspace/*": ["dist/libs/*"] }
into your tsconfig.lib.json files. This should resolve the problem.
Don't override "baseUrl" and "paths" in any of child tsconfig! Put all of your "paths" in tsconfig.base.ts!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With