Search code examples
typescriptneovimyarn-v2yarnpkg-v2typescript-language-server

Can not find module when adding repo with yarn as package manager


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": "[email protected]: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:


Solution

  • 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.