0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

typescript x viteでのxmlファイルインポート時に発生する警告文を踏み潰す方法

0
Posted at

本記事の対象者

・vite初心者
・typescript初心者
・僕みたいな情弱

初めに

typescriptとviteを使用している際、xmlファイルをimportすると警告文が発生すると思います。今回はそれを1秒で簡単に対策できる方法について共有したいと思います。(あと自分のメモ用としても残したいので)

対策方法

通常バンドラーとしてviteを採用している場合、pngやfont,xmlなどのアセットファイルは以下のようにimport文を使用してインポートすると思います。

export import XmlFile from "../../public/fonts/target-file-name.xml";

しかしxmlをそのままimportしようとすると、
モジュール'{対象xmlのパス}'またはそれに対応する型宣言が見つかりません
と表示されてしまいます...正直うざいし黙れってなりますよね

ですが魔法の言葉を少し付け足すだけで問題は解決してしまいます。?urlをパスの最後に付け足すだけです。

export import XmlFile from "../../public/fonts/target-file-name.xml?url";

これで黙ります

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?