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

react-serverでtailwindcssが動かなかった

Last updated at Posted at 2025-03-06

追記

PR出したのでもうドキュメント通り動くはずです
https://github.com/lazarv/react-server/pull/172#event-16721617773

はじめに

react-serverの検証をしてる際にドキュメント通りやってtailwindが動かなかったので対処法を取り急ぎ書きます。PR出して修正するかもですが

バージョン4の場合

1. vite.config.jsを修正

vite.config.js
import { defineConfig } from "vite";
// import tailwindcss from "tailwindcss";
import tailwindcss from "@tailwindcss/vite"; // ←これにする

export default defineConfig({
  plugins: [
    tailwindcss(),
  ],
});

2. App.jsxとmain.jsxにimport React from 'react'を入れる

インポートしないとコンソールで怒られます

edit:
そもそもviteセットアップするドキュメントではreactをアンインストールしてるから、必要ないかも(?)→必要なさそうでした。

バージョン3の場合

サーバ立ち上げた際に以下のエラーが出ます(実際はもっと長いですが)

It looks like you're trying to use tailwindcss directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package, so to continue using Tailwind CSS with PostCSS you'll need to install @tailwindcss/postcss and update your PostCSS configuration.

GPT曰く
エラーの原因は postcss.config.jsがESモジュール(type: "module")に対応していないためです。package.jsonに "type": "module"が含まれていると、Node.jsはすべての.jsファイルをESモジュールとして扱います。しかしpostcss.config.jsはCommonJS形式である必要があります

postcss.config.jsの拡張子をjsからcjsにする

これでCommonJSとして認識されるようです

'module' is not definedが出る場合

postcss.config.jsやtailwind.config.jsで'module' is not definedが出る場合、export defaultにすると

おわりに

とりあえずこれで動きました

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