Berry: [Bug] @types packages are not resolved by VSCode TypeScript pnpify SDK

Created on 23 Sep 2020  ยท  10Comments  ยท  Source: yarnpkg/berry

_Created from this Discord conversation._

We have a monorepo where the root contains only dev dependencies like Prettier, and it uses PnP.

Then we have several projects in subfolders, like app1, app2, etc. Some of them are on Yarn 1, some on Yarn 2, but they all use the node-modules linker.

It all looks like this:

.
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ yarn.lock
โ”œโ”€โ”€ .yarnrc.yml
โ”œโ”€โ”€ .pnp.js
โ”œโ”€โ”€ app1/
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ yarn.lock
โ”‚   โ”œโ”€โ”€ node_modules
โ”‚   โ””โ”€โ”€ .yarnrc.yml
โ””โ”€โ”€ app2/
    โ”œโ”€โ”€ package.json
    โ”œโ”€โ”€ yarn.lock
    โ”œโ”€โ”€ node_modules
    โ””โ”€โ”€ .yarnrc.yml

We've ran yarn dlx @yarnpkg/pnpify --sdk vscode which made most of the things work, however, TypeScript doesn't understand imports that depend on @types/... packages:

Screen Shot 2020-09-23 at 18 15 46-shadow

mobx-react and formstate contain .d.ts files so everything work fine, but react, next/router and @apollo/client depend on @types packages and those don't work.

It's also worth noting that this is purely a dev-time / VSCode issue โ€“ we can use tsc on app1 and app2 just fine.

This is our root .yarnrc.yml โ€“ I believe it is configured correctly:

yarnPath: '.yarn/releases/yarn-2.2.2.cjs'
pnpIgnorePatterns:
  - 'app1/**'
  - 'app2/**'

Environment:

  • OS: macOS
  • Node version: 12
  • Yarn version: 2.2.2.
bug upholded

Most helpful comment

In any event, looks like I'll have to stick with Yarn 1 for now.

@NickHeiner You can use the node-modules linker in V2, which should be much better than V1, until this is solved

yarn config set nodeLinker node-modules && yarn install

All 10 comments

Could you attach a repro we can clone and test with please?

I may be experiencing the same issue. You can clone and test with: https://github.com/NickHeiner/devtools/tree/yarn-2.

I tried to follow the Editor Setup instructions. However, in step 3 and 4, there was no valid option for a workspace version of typescript to use.

image

In any event, looks like I'll have to stick with Yarn 1 for now.

In any event, looks like I'll have to stick with Yarn 1 for now.

@NickHeiner You can use the node-modules linker in V2, which should be much better than V1, until this is solved

yarn config set nodeLinker node-modules && yarn install

Hi! ๐Ÿ‘‹

This issue looks stale, and doesn't feature the reproducible label - which implies that you didn't provide a working reproduction using Sherlock. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).

Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolutions). It helps us help you! ๐Ÿ˜ƒ

If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the upholded label. Thanks for helping us triaging our repository! ๐ŸŒŸ

I'm experiencing the same issue. Is it berry related or VSCode?

Similar issue, which would probably be fixed by this.

I have a node_modules project in the same monorepo root as other workspaces which use PnP. It's in its own separate folder.

The NM linker project cannot find any of its own dependencies when using the pnpify sdk typescript.

Was able to fix this, but it will need #2055 and https://github.com/arcanis/TypeScript/pull/3 to be merged and released.

I made a branch on my fork which you can install via:

yarn set version from sources --repository https://github.com/andreialecu/berry.git --branch aa/typescript-patch

(it includes a fix for this issue and for the one at #1932)

Important: You will need to list any non-pnp projects in pnpIgnorePatterns then run yarn install.

Forgot to mention that the patch in my comment above only works for typescript 4.0.x currently.

Similar issue.

Environment:
OS: Mac OS
Node version: 10.22.1
yarn version: 2.3.3
typescript version: 4.0.5

yarn config set nodeLinker node-modules && yarn install

works for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bessonov picture Bessonov  ยท  4Comments

juanpicado picture juanpicado  ยท  4Comments

milichev picture milichev  ยท  3Comments

thealjey picture thealjey  ยท  4Comments

chrisands picture chrisands  ยท  3Comments