tsx cannot find module 'xxx'
Asked Answered
I

2

5

I am using yarn v2 to install the dependency package, and using yarn start command to start the project smoothly, but vscode always reminds me that I can't find any local modules.

enter image description here

And here is my tsconfig.json file:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}

Here is my folder structure:

enter image description here

Itching answered 7/3, 2020 at 4:7 Comment(0)
T
9

You can use @yarnpkg/sdks package (which is a part of Yarn 2+)

You can enable PnP support in VS Code via:
yarn dlx @yarnpkg/sdks vscode
This will generate tssdk and modifies your .vscode/settings.json to add TypeScript compiler-wrapper inside tssdk as a Workspace TypeScript compiler. You should run VS Code, open any TypeScript file and in the bottom right side of the window click on TypeScript version. Select Use Workspace Version from dropdown menu to actually use Workspace Compiler, its version has the suffix -sdk.

You can also read Yarn 2+ docs regarding VSCode integration here:
https://yarnpkg.com/getting-started/editor-sdks#vscode

Thickset answered 10/3, 2020 at 10:29 Comment(1)
Thank you! The Use Workspace Version was the piece I was missing.Bedevil
B
0

What the default Nest.js installation nest new project-name does is uses yarn's nodeLinker by creating a .yarnrc.yml in the project root:

nodeLinker: node-modules

You can add this file to an existing yarn project, then run yarn and it will generate a node_modules directory that will make VSCode happy again.

Bargeboard answered 27/9, 2023 at 3:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.