【TypeScript】Cannot find module … or its corresponding type declarations の解決法
困ったこと
import ArticleHeader from "@/app/__component/sampleComponent";
Cannot find module '@/app/__component/sampleComponent' or its corresponding type declarations
TypeScriptで@
を使った絶対パスでimport
していたら、コンパイル時に上記のようなエラーとなった。
解決法
tsconfig.json
にaliasの定義を追加する。
"compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] }