2

I'm having trouble adding a github repository to my Yarn monorepo. The repo I want to add has TS compiled code for commonjs an es module in dist folder.

I've added the repo, which I want to consume, to the package.json in this format:

  "dependencies": {
    "@foo/some-lib": "git@github.com:zantinger/some-lib.git"
  }

but I keep getting the error message "Cannot find module..." (from my LSP language server, I think). enter image description here

I can confirm, that webpack is able to build the project, even with the diagnositc error from the LSP-server. So it seems to be a tsserver issue.

Here's what I've tried so far:

  • I've confirmed that the package exists in the github repository and that I have access to it.
  • I've tried cleaning the Yarn cache and reinstalling the dependencies, but that didn't fix the issue.
  • I've checked the .yarnrc file and confirmed that there are no conflicts with other dependencies.
  • I'm using Yarn 2 as a monorepo with zero install and PnP active.
  • I've also tried adding the repository URL to the resolutions field in package.json, but that didn't help either.
  • I'm using typescript in both project.
  • I found the added repo in .yarn/cache/... as .zip files

Is there a way to add a github repository to a Yarn monorepo with zero install and PnP active? Any suggestions on what else I could try to resolve this issue?

I'm using:

Feel free to have a look at my example repos:

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Zantinger
  • 167
  • 3
  • 16
  • can you please provide result of `yarn run consumer --verbose`, basically, try running the consumer project with the --verbose flag to get more information on what Yarn is doing when resolving the dependency... – Manoj Kumar Apr 07 '23 at 18:34
  • you might want to recheck the main and module index.. { .. "main": "dist/lib/es5/index.js", "module": "dist/lib/es6/index.js", .. } ... you must make sure that the compiled files actually exist in the dist folder of the library repository and that they are being committed to the repository. – Manoj Kumar Apr 07 '23 at 18:39
  • Hi @ManojKumar, it seems that --verbose is an unsuported option. The compiled files exists in the consumer repo, because of zero-install of yarn: https://github.com/zantinger/some-consumer/blob/main/.yarn/cache/%40foo-some-lib-git%2Bssh-60e30875a5-cca4d6652f.zip I'm able to open the zip files with neovim and I see the compiled files and the type definitions (.d.ts). – Zantinger Apr 07 '23 at 18:48
  • @Zantinger if you ignore TS errors, can you import it in runtime? Or with async `import()`? (i.e. is it a type error, or a runtime error ) – Dimava Apr 07 '23 at 21:05
  • Interesting. webpack can successfully build the code. The console.log built into the code is displayed to me in the browser. Even if the position displayed as an error by the LSP server is not provided with @ts-ignore. – Zantinger Apr 08 '23 at 16:30
  • I was able to solve the problem myself now. typescript needs a skd from yarn. I had tried to install it before, but I didn't realize that typescript had to exist as a dependency in the root directory. I only had typescript in the workspaces as a dev-dependency. adding typescript as a dependency at root level and running yarn dlx @yarnpkg/sdks vim again fixed the problem now. Many thanks anyway to those who took the time for my problem. – Zantinger Apr 11 '23 at 09:50
  • Please do not add answers to the question body itself, nor as comments. Instead, you should add it as an answer. [Answering your own question is allowed and even encouraged](https://stackoverflow.com/help/self-answer). – Adriaan Apr 11 '23 at 09:55

2 Answers2

2

I was able to solve the problem myself now. typescript needs a skd from yarn. I had tried to install it before, but I didn't realize that typescript had to exist as a dependency in the root directory. I only had typescript in the workspaces as a dev-dependency. adding typescript as a dependency at root level and running yarn dlx @yarnpkg/sdks vim again fixed the problem now.

Zantinger
  • 167
  • 3
  • 16
1

@Zantinger have already given the solution, but to anyone still in doubt, there's a page in Yarn docs specific to this subject. You can check the best option for you, for example, I use neovim, the same as in the question, so following the doc, I ran yarn dlx @yarnpkg/sdks base and bingo! It works.

oould
  • 11
  • 3