question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Yarn PnP module resolution

See original GitHub issue

The Files.resolve function exported by vscode-languageserver fails to resolve node modules in a Yarn PnP environment. This causes for example vscode-eslint to stop working when using PnP (see microsoft/vscode-eslint#601).

In order to support Yarn PnP, the project’s local .pnp.js file needs to be required.

Quick pseudocode for how this should work:

if (is yarn pnp) {
  require(cwd + '/.pnp.js')
}

// ...rest

I think this has to be done at some point during the app script in Files#resolve:

https://github.com/microsoft/vscode-languageserver-node/blob/4d256255c2f2e00a2f6214c581e32ade7c8acc1e/server/src/files.ts#L52-L68

Edit: Or better yet, add --require /path/to/.pnp.js to the node CLI arguments here:

https://github.com/microsoft/vscode-languageserver-node/blob/4d256255c2f2e00a2f6214c581e32ade7c8acc1e/server/src/files.ts#L87-L90

That would be the recommended approach by the Yarn docs.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dbaeumercommented, Aug 6, 2019

Discussing this in the ESLint repository is the best location. It was a mistake to add the resolve feature to the server in the first place and I actually will not improve this further. Loading stuff from the workspace folder should be best done by the extension that wants to load these files.

So I close the issue in favour of the having a solution in ESLint.

1reaction
teoxoycommented, Jul 27, 2019

I am using yarn v2 (berry) for a monorepo, taking advantage of pnp and workspaces but vscode-eslint doesn’t work because of this issue.

The problem that I see is that on the consuming side how would a server know that something got installed using yarn --pnp. We would need another setting for this.

pnp comes by default with yarn v2 (berry). Regarding v1, I’m not sure how to check if pnp is enabled or not…

I would like to start a PR myself but there are some unknowns:

  • should only yarn v2 be supported?
  • how can this feature be tested?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Plug'n'Play | Yarn - Package Manager
The Node resolution doesn't have to iterate over the filesystem hierarchy nearly as much as before (and soon won't have to do it...
Read more >
Module resolution breaking for Yarn PNP in TS 4.8 #50547
Our repo is using Yarn Berry workspaces with PNP, and after upgrading to 4.8, we are seeing a lot of errors resolving modules...
Read more >
Compatibililty with Yarn PnP (Plug and Play) feature - YouTrack
Hi, I just wanted to know if there are some plans to support the new feature of Yarn (the Pnp or Plug and...
Read more >
wheatstalk/cdk-lambda-pnp - npm
Deploy your AWS Lambdas from a Yarn PnP workspace using the CDK. ... module resolution; Supports hard-to-bundle packages if yarn PnP ...
Read more >
VS Code and Yarn PnP - typescript - Stack Overflow
Cannot find module 'react' or its corresponding type declarations. It builds and runs via webpack. This appears to be a VS Code/sdk artifact....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found