反应有TS错误的导入svg:“找不到模块'../images/bar.svg'。”

时间:2020-03-22 05:22:19

标签: reactjs typescript svg import

.tsx文件中,我可以导入.svg文件,并设置以下tsconfig.jsonindex.d.ts个文件。

tsconfig.json

"compilerOptions": {...},
"include": ["./app/src/index.d.ts"]

index.d.ts

declare module "*.svg" {
  const content: string;
  export default content;
}

然后我像这样导入 import image from "../images/bar.svg";

没有webpack编译错误,使用图像没有问题,但是只是从vscode中得到了ts错误: Cannot find module '../images/bar.svg'.

如何清除此错误?

0 个答案:

没有答案