Search code examples
node.jsvisual-studio-codeeslintyarnpkgprettier

Cannot find module `prettier' in VSCode with Yarn PnP (Extensions do not work with YARN PnP)


Since upgrading to Yarn 2+ (Berry), and later Yarn 4 with PnP support, VSCode cannot resolve locations for extensions prettier, eslint and others. In VSCode I receive the following error message:

Error: Cannot find module 'prettier'

I've ensured prettier is installed correctly, updated every prettier config possible, and nothing seems to work.


Solution

  • TLDR: yarn dlx @yarnpkg/sdks vscode

    VSCode couldn't resolve prettier inside of node_modules since that folder doesn't exist when PnP is enabled. The fix was super easy, as described in Yarn's documentation on Editor SDKs.

    From Yarn Docs: Editor SDKs

    "Smart IDEs (such as VSCode or IntelliJ) require special configuration for TypeScript to work when using Plug'n'Play installs."

    This script installed and configured a bunch of files in my .yarn directory, and immediately solved my issues. Check out the links above to read more.