typescriptyarnpkgyarn-workspaces

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.


Solution

  • Similar issue here. This error is coming from the linter; I think it's checking inside the package lock file (which does not exist as yarn is using yarn.lock).

    Please check these in your VSCode user settings.json:

    "eslint.packageManager": "yarn",
    "prettier.packageManager": "yarn",
    "npm.packageManager": "yarn"
    

    These settings have worked for me. YMMV.

    EDIT: changed punctuation