nishimura.clubnishimura.club

Next.js コンポーネントのimportで相対パスを使う

作成日
2021-05-17
更新日
2021-05-18

Absolute Imports and Module path aliasesに記載してありました。

1. jsconfig.json または tsconfig.jsonに設定する

// tsconfig.json or jsconfig.json { "compilerOptions": { "baseUrl": ".", "paths": { "@/components/*": ["components/*"] } } }

2. import文を変更してみる

import Pagination from '@/components/pagination'

3. devサーバの再起動

devサーバの再起動しないと、jsconfig.jsonが読み込まれないようです。

自分のもの

{ "compilerOptions": { "baseUrl": ".", "paths": { "@/components/*": ["components/*"], "@/lib/*": ["lib/*"], "@/styles/*": ["styles/*"] } }, }

Related