無法在打字稿中導入 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章