【Jest, Typescript】テスト実行で”Cannot find module or its corresponding type declarations”のエラーとなる場合

スポンサーリンク

Jest実行で”Cannot find module or its corresponding type declarations”のエラー

Jest + Typescript でテスト実行した際に”Cannot find module or its corresponding type declarations”となってファイルの import に失敗する場合があります。

この場合はプロジェクトルートに shims-vue.d.ts の名前で下記ファイルを作成して見てください。

//shims-vue.d.ts
declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}

これで再度実行するとエラーが出なくなるかと思います。

これは .vue ファイルを Typescript のファイルとして認識させるために必要らしいです。

参考

GitHub - microsoft/TypeScript-Vue-Starter: A starter template for TypeScript and Vue with a detailed README describing how to use the two together.
A starter template for TypeScript and Vue with a detailed README describing how to use the two together. - microsoft/TypeScript-Vue-Starter

未経験、異業種からIT業界に転身。フロントエンジニア。主にJavascript(React.js)をつかったWEBアプリ開発にたずさわる。
お問い合わせ、ご相談など → genpsp10@gmail.com

psp7をフォロー
プログラミング
スポンサーリンク
psp7をフォロー
ハトらぼ

コメント