Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yarn: cannot find module

I have a yarn workspace set up with folders public and server. I am using TypeScript in VS Code. On any module that doesn't have types pre-installed with the package, I get the error in VS Code:

Cannot find module 'x'

However, the IntelliSense will show x as a suggestion. I have both x and @types/x and it seems like it's no difference if I install @types/x. Thanks

Windows 1909 (Latest)
Visual Studio Code 1.43 (Latest)
TypeScript ^3.8.3 (Latest)
Yarn 2.0.0-rc.30 (Latest)

Also, I tried to find type roots for yarn, but didn't. Could someone please tell me where the type root directry is.

like image 910
tscpp Avatar asked Nov 18 '25 06:11

tscpp


1 Answers

From the docs:

To support features like go-to-definition a plugin like ZipFS is needed.

  1. Run the following command, which will generate a new directory called .yarn/sdks:

    yarn dlx @yarnpkg/sdks vscode
    
  2. For safety reason VSCode requires you to explicitly activate the custom TS settings:

  3. Press ctrl+shift+p in a TypeScript file

  4. Choose "Select TypeScript Version"

  5. Pick "Use Workspace Version"

like image 153
dan-klasson Avatar answered Nov 20 '25 23:11

dan-klasson