5

I created a monorepo with lerna (the code in github).

Inside I have two packages each package export sum function.

In app1 folder I want to import this function but vscode doesn't find the function.

Not sure why. I set everything correctly, and vscode should be offer from two paths:

@packages/pck1
@packages/pck2

/tsconfig.json

{
  "extends": "./tsconfig.build.json",

  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@packages/*": ["packages/*/src"]
    },
    "jsx": "react",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "types": []
  }
}

If you can clone my repo - run npm install then open vscode and go to apps/app1/src/index.ts and write sum. wait for typescript to find the function. you will get:

enter image description here

can't find the reason, any help will be appreciated.

0

1 Answer 1

2

If you are using scoped packages, they would be called @pck1 and @pck2, not @packages/SOMETHING as your top-level tsconfig.json suggests.

I could get your example working as follows:

Add these compilerOptions to apps/app1/tsconfig.json:

"baseUrl": ".",
"paths": {
  "@pck1": ["../../packages/pck1/src"]
}

And change apps/app1/src/index.ts:

import { sum } from '@pck1';
sum(9,9);

Your basic mistake is: You consider packages part of the packages' names but it is just a directory. I have created a PR on github for this: https://github.com/wizardnet972/lerna-test/pull/1

I have a similar lerna test project on github: https://github.com/gflohr/lerna-deps. It is explained in a blog post http://www.guido-flohr.net/lerna-mono-repos-with-internal-dependencies/. Maybe you can use that as a starting point.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.