7

I'm trying to setup a Monorepo with Lerna and yarn workspaces, but the thing that I cannot get to work is where I try to add packages as a dependency of an other local package

So, what does that mean

I have a project structure like this

/
 packages/
          a/
            src/a.ts
          b/
            src/b.ts
          ab/
            src/ab.ts

Very basic, its for testing only. I've also create a public repository with this structure and all the other files in place. You can follow the readme to reproduce the problem.

So, a.ts looks like this

export class A {
    get(): string {
        return 'a';
    }
}

b.ts looks very similar and ab.ts uses both as follows

import { A } from '@myScope/a';    
import { A } from '@myScope/b';

export class Ab {
    getA(): A {
       return new A();
    }
    getB(): B {
       return new B();
    }

Now, when I build these with lerna run build, which is nothing more than tsc on all three files, I get errors, telling me that the modules imported in ab.ts cannot be found. So the question is, how can I add my two local packages?

Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
  • 2
    You don't have `@myScope/a` and `@myScope/b` in the `dependencies` of `package.json` in `@myScope/ab`, so `lerna bootstrap` does not add them to `node_modules` in `ab` where TypeScript expects them to be – artem May 07 '19 at 20:30
  • 1
    Thats it @artem, I needed to do `lerna add ...`. Thanks a lot for pointing that out! – Jeanluca Scaljeri May 07 '19 at 20:56

0 Answers0