简体   繁体   中英

VSCode: Cannot find module 'antd' or its corresponding type declarations

I have installed antd to my typescript project:

"antd": "^4.6.2",

It works fine and my project builds using the antd components (webpack used to build) but inside VSCode I don't get typings and it gives me this error:

在此处输入图像描述

Here is my tsconfig.json

{
    "compilerOptions": {
      "outDir": "./dist/",
      "noImplicitAny": true,
      "module": "es6",
      "target": "es5",
      "jsx": "react",
      "allowJs": true,
      "allowSyntheticDefaultImports": true,
      "sourceMap": true,
      "moduleResolution": "node",
    }
  }

What am I doing wrong? Antd is meant to include it's own typings so why doesn't VSCode recognise it?

The issue appears to be known issue with VSCode: https://github.com/Microsoft/TypeScript/issues/10346

It can be fixed by manually adding

/// <reference path="path/types.d.ts" />

Then doing F1 -> reload window.

Or apparently by installing vscode typescript hero plugin. I can't confirm plugin works as I had already fixed with manual reference and reload.

add tsx file to tsconfig.json:

{
    ...
    "include": [
        "./**/*.ts",
        "./**/*.tsx"
    ],
    ...
}

I installed the module, but still had this message

F1 -> reload window helped me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM