reactjs - React import svg 出现 TS 错误:“找不到模块 '../images/bar.svg'。”
问题描述
在.tsx
文件中,我可以导入.svg
文件,设置以下tsconfig.json
和index.d.ts
文件。
tsconfig.json
"compilerOptions": {...},
"include": ["./app/src/index.d.ts"]
索引.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'.
如何消除此错误?
解决方案
推荐阅读
- javascript - 从 S3 编译资产
- yii2 - 路由部分的 Yii2 规则
- javascript - Array.fill() 保留先前选择的月份日期
- javascript - 在nodejs中将数组转换为json格式
- reactjs - 如何使用 webpack 和 react 使用不同项目常见的节点模块依赖项
- php - Xampp 中的 php 5.6 中的多线程
- vhdl - 执行期间 VHDL 复位
- c# - 如何发布到 RESTful Web API
- amazon-web-services - AWS:Amazon Cognito 与 STS 和 SAML
- reactjs - 打字稿导入模块问题