无法在打字稿中导入 svg 文件 - Unable to import svg files in typescript

问题:

In typescript(*.tsx) files I cannot import svg file with this statement:typescript(*.tsx)文件中,我无法使用以下语句导入 svg 文件:

import logo from './logo.svg';

Transpiler says: [ts] cannot find module './logo.svg'. Transpiler 说: [ts] cannot find module './logo.svg'. My svg file is just <svg>...</svg> .我的 svg 文件只是<svg>...</svg>

But in .js file I'm able to import it without any issues with exact the same import statement.但是在.js文件中,我可以使用完全相同的导入语句导入它而不会出现任何问题。 I suppose it has something to do with type of svg file which must be set somehow for ts transpiler.我想它与 svg 文件的类型有关,必须以某种方式为 ts 转译器设置。

Could you please share how to make this work in ts files?你能分享一下如何在 ts 文件中进行这项工作吗?


解决方案:

参考一: https://en.stackoom.com/question/31cya
参考二: https://stackoom.com/question/31cya
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章