可视代码显示无法找到绝对导入的模块警告

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

我使用typescript并做出反应并设法通过遵循此link在VS Code中进行绝对导入,我遵循除步骤2之外的所有步骤,并且代码可以无问题地执行。但是在VS Code编译器中它会在图像中显示警告"Cannot find module",那么这是一种清除此警告的方法吗?

image

这是我的tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",   
    "sourceMap":  true, 
    "baseUrl": "./",
    "paths": {
      "custom": ["src/components/custom/"]
    }
  } 
}
typescript visual-studio-code
1个回答
0
投票

在你的tsconfig.json中如果你在*键中添加paths并且值应该修复它,例如:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",   
    "sourceMap":  true, 
    "baseUrl": "./",
    "paths": {
      "custom/*": ["src/components/custom/*"]
    }
  }
}

这应该使导入指向文件夹custom下的所有组件,并且它们可以作为custom/fileName导入。它也应该自动完成。

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