microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.88k stars 12.47k forks source link

TypeScript type resolve fails for symlinked folders (pnpm) #51684

Open kamnakis opened 1 year ago

kamnakis commented 1 year ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce:

Here is a video of the issue https://user-images.githubusercontent.com/33131460/203819438-464d7205-ab57-4b96-8f88-4d38b916fca5.mp4

  1. Clone https://github.com/kamnakis/vscode-symlink-issue-reproduction
  2. Install pnpm globally if you haven't already.
  3. Run pnpm i
  4. Go to node_modules/react-router-dom/dist/index.d.ts
  5. Types from react-router and @remix-run/router are not resolved even though they are defined in the dependencies of react-router-dom.

I think the issue is happening because the node_modules/react-router-dom is a symlink and vs code looks at the copy and not the original folder.

mjbvz commented 1 year ago

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

kamnakis commented 1 year ago

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

Just checked! Yes it does!

kamnakis commented 1 year ago

Since this was moved in the TypeScript repository, let me share something I noticed while investigating on this error. Hope it helps.

Let's say I import a third party module (e.g. react-router-dom) and the ./node_modules/react-router-dom is a symlink folder.

Here is a video:

https://user-images.githubusercontent.com/33131460/205047528-d083599e-3498-46e5-89d4-ed40f223fda9.mp4

xania commented 1 year ago

Typescript resolve the symlinked dependency (installed using pnpm) but pins the resolved path to physical folders. for me this becomes an issue when a new version of the dependency is installed but TypeScript intellisense keeps pointing to the old version. The only workaround I know is restarting VS Code. Is there a better / another workaround?

EDIT: Asking the question helps to think clearer. A better workaround is to restart just the typescript server image

kamnakis commented 1 year ago

My issue seems to be fixed with Typescript v5.04

xania commented 1 year ago

My issue seems to be fixed with Typescript v5.04

Just for the reference, mine issue is still there even with v5.04