yarnpkg / yarnpkg/berry

[Bug?]: Cannot run `require` from inside VSCode extension

Open
#4,686 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
8.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Self-service
  • I'd be willing to implement a fix
Describe the bug

When using yarn pnp, Cmd+Click doesn't work in VSCode for imported scss files from external deps, e.g.

@import "~@blueprintjs/core/lib/scss/variables";

...

This is because microsoft/vscode-css-languageservice hardcodes a node_modules path here: https://github.com/microsoft/vscode-css-languageservice/blob/045b4764e36648a29cb3970e6733b35a0085600d/src/services/cssNavigation.ts#L347

I tried to fix this by changing the path resolution to use require.resolve, but I get a MODULE_NOT_FOUND error. I think this is expected, because VSCode is likely not running this code with the pnp loader.

I'd like to fix this, either on the VSCode side or the yarn side (or both!), but I'm not sure how to proceed. Any tips?

No repro provided (since the hard-coded node_modules is apparent). Let me know if you need more info though!

To reproduce

n/a

Environment
n/a
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with cssNavigation.ts at the linked line and investigate how require.resolve behaves inside a VSCode extension under Yarn Plug’n’Play. Establish a reproducible case for the external SCSS import and determine whether the fix belongs in VSCode, Yarn, or both; done means Cmd+Click resolves the import without MODULE_NOT_FOUND.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.