4
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?

More than 1 year has passed since last update.

【初心者メモ】Gatsby+TypeScriptにおけるCSS Modulesエラー

Last updated at Posted at 2022-05-30

事象

GatsbyのチュートリアルをTypeScriptに読み替えながら実施している際、以下のエラーが吐かれた。

// Cannot find module './style.module.css'.
import { style } from "./style.module.css";

解決策

next.jsでの対処方法を参考に、以下の手順で解決した。

  1. プロジェクトフォルダ直下にgatsby-env.d.tsを作成
  2. tsconfig.jsonのincludeに上記のファイルを追加する
gatsby-env.d.ts
declare module "*.css";
declare module "*.scss";
tsconfig.json
  "include": [
    ...,
    "./gatsby-env.d.ts"
  ],

参考

https://blog.shimar.me/2020/12/05/nextjs-css-cannot-find-module
https://www.gatsbyjs.com/docs/tutorial/part-2/

4
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
4
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?