Sample repo illustrating an issue with TypeScript in a lerna-based monorepo.
I found two workarounds for the issue:
- Instead of doing
lerna bootstrap
, if we dolerna bootstrap --hoist
, it works. This is due to--hoist
makinglerna
unify the commonrxjs
dependency, and puts it in thenode_modules
in the root, so there is no duplication any more. - Add
rxjs
as a dependency in the rootpackage.json
, and move it to thepeerDependencies
in the actual packages. (This results in the same ultimate setup as whatlerna bootstrap --hoist
produces.)
I pushed this fix to thepeer-dep
branch.
Clone the repo, and install the dependencies.
npm install
Then execute
lerna bootstrap
The above command installs the dependencies for the two packages. Since the dependency from lerna-typescript-demo-ts
to lerna-typescript-demo-base
is an internal cross-package dependency, lerna
sets that up with a symbolic link pointing to the directory of the other package. I suspect that this is what's causing the compilation error.
Then enter the directory of TypeScript package, and try to transpile.
cd packages/lerna-typescript-demo-ts
npm run transpile
The transpilation will fail with the following error:
error TS2345: Argument of type 'UnaryFunction<Observable<Bar[]>, Observable<Bar[]>>' is not assignable to parameter of type 'UnaryFunction<Observable<Bar[]>, Observable<Bar[]>>'.
Types of parameters 'source' and 'source' are incompatible.
Type 'Observable<Bar[]>' is not assignable to type 'Observable<Bar[]>'. Two different types with this name exist, but they are unrelated.
I suspect that this is somehow caused by the usage of the symbolic linking, because if we
- Delete the
node_modules
folder insidepackages/lerna-typescript-demo-ts
- Execute
npm install
insidepackages/lerna-typescript-demo-ts
(so that it pulls down the dependency from NPM instead of linking) - Do the transpilation again with
npm run transpile
Then it succeeds.