tsx找不到模块'xxx'

问题描述 投票:0回答:1

[我正在使用yarn 2安装依赖项包,并使用yarn start命令顺利启动项目,但是vscode总是提醒我找不到任何本地模块。

enter image description here

这是我的tsconfig.json文件:

{
  "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"
  ]
}

这是我的文件夹结构:

enter image description here

typescript yarn tsx yarn-v2
1个回答
1
投票

您可以使用@yarnpkg/pnpify程序包(它是Yarn v2的一部分)

首先,您应该将包添加到您的项目中:yarn add -D @yarnpkg/pnpify

然后您可以通过以下方式在VS Code中启用PnP支持:yarn pnpify --sdk这将生成tssdk并修改您的.vscode/settings.json以在tssdk内添加TypeScript编译器包装,作为Workspace TypeScript编译器。您应该运行VS Code,打开任何TypeScript文件,然后在窗口的右下角单击TypeScript版本。从下拉菜单中选择Use Workspace Version以实际使用Workspace Compiler,其版本带有后缀-pnpify

您还可以在此处阅读有关VSCode集成的Yarn v2文档:https://yarnpkg.com/advanced/editor-sdks#vscode

© www.soinside.com 2019 - 2024. All rights reserved.