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

React CSSファイルをあてる

Last updated at Posted at 2025-05-18

前回記事(環境構築)のつづき

公開後にコメントをいただき、記載内容に誤りがあることがわかりました。参考にされる方は、最後のコメントのやりとりまでお読みください。

App.jsx に css をあてる

今回のエラーポイント

スクリーンショット

ブラウザ側で出たエラー

image.png

エラー発生時のコード

App.jsx

import { useState } from 'react'
// ファイル名 "style.module.css"だとエラーが出る バージョンの違い?
import './custom.modules.css'
// import './App.css'

function App() {
  const [count, setCount] = useState(0)

  return (
    <div className="App">
      <h1 className='text1'>Hello World</h1>
      <h1 className='text2'>Hello World2</h1>
    </div>
  )
}
export default App

インストールした React のバージョン

package.json で確認すると、19.1.0 になっています。

image.png

やってみたこと

css のファイル名を変更してみた 

custom.mocules.css を、custom.css に変更して再度トライしました。

結果

成功しました :tada:

image.png

エラー解消時のコード

App.jsx

import { useState } from 'react'
// ファイル名 "style.module.css"だとエラーが出る バージョンの違い?
import './custom.css'

function App() {
  const [count, setCount] = useState(0)

  return (
    <div className="App">
      <h1 className='text1'>Hello World</h1>
      <h1 className='text2'>Hello World2</h1>
    </div>
  )
}
export default App

customs.css

.text1{
  color: red;
}

.text2{
  color: blue;
}

結果から逆算して得られた結論

学習記録のため残していますが、記載内容に誤りがあります。コメント欄にて訂正しています。

React の最新バージョン(19.1.0)では読み込ませたい css ファイル名を、"〇〇.css" にする必要がある。"〇〇.〇〇.css" にするとエラーになる。

0
0
4

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