1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

(Next.js) TypescriptファイルでCSS/SCSSファイルを読み込む方法

Posted at

##1. 問題
Next.jsプロジェクト内のtypescriptファイルでCSSファイルをimportで読み込もうとすると、エラーになります。

sample.ts
import style from "./styles.css"

//下記のようなエラーが出て読み込めない
TS2307: Cannot find module './styles.css

##2.解決策
「next-env.d.ts」というファイルがあるはずなので、そこに下記のように追加で記述。
無事Next.jsプロジェクト内のtypescriptファイルでcss/scssが読み込めるようになります。

next-env.d.ts
declare module '*.css';
// or scss
declare module '*.scss';

参考
How to fix TypeScript cannot find module CSS/SCSS in Next.js

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?