Search code examples
javascripttypescriptlerna

Imports from a lerna shared package seem to require src at the end of the name (Typescript/javascript)


I have a simple lerna project like:

Project
 |    
 +-- packages
 |  |  
 |  +-- shared
 |  |  |
 |  |  +-- src
 |  |       |  
 |  |       +-- index.ts
 |  |       +-- someDir   
 |  |
 |  +-- usesShared
 |
 +

My index.ts has entries like:

export * from "./someDir";

When I import a class from someDir in a "usesShared" class, I am having to put /src at the end of the import like:

import {GreatClass} from "myShared/src";

I am new to Typescript, javascript, & lerna but this seems wrong to me. It seems like it should just be:

import {GreatClass} from "myShared";

Can someone point me towards how to fix this? Does this have something to do with lerna or am I missing something in package.json?


Solution

  • In "shared" or "myShared" (not sure what you named it), create index.ts:

    export * from "./src";
    

    To import the class from usesShared:

    import { GreatClass } from "../myShared";