reactjs - Cannot build frontend using Vite, TailwindCSS with PostCSS - Stack Overflow

admin2025-04-20  5

10:04:32 PM [vite] Internal server error: [postcss] 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. Plugin: vite:css File: ...

10:04:32 PM [vite] Internal server error: [postcss] Missing > "./components" specifier in "tailwindcss" package Plugin: vite:css File: ...

I developed my chat app so I wanted everything updated so I removed node_modules then npm install and build then the above error keeps coming. It has to be something related to dependencies because it was working before I remove node_modules.

npm cache clean --force

npm install -D tailwindcss autoprefixer postcss

I uninstalled them and did the above commands but it keeps giving me above error. What is the relation of PostCSS to TailwindCSS why are both dependent on each other?

npx tailwindcss init

also it says

npm error could not determine executable to run npm error A complete log of this run can be found in: /home/amosmurmu/.npm/_logs/2025-01-23T15_39_50_870Z-debug-0.log

I also tried to change Node.js version using NVM but it gives structured clone error so its not Node.js or NPX or NPM.

10:04:32 PM [vite] Internal server error: [postcss] 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. Plugin: vite:css File: ...

10:04:32 PM [vite] Internal server error: [postcss] Missing > "./components" specifier in "tailwindcss" package Plugin: vite:css File: ...

I developed my chat app so I wanted everything updated so I removed node_modules then npm install and build then the above error keeps coming. It has to be something related to dependencies because it was working before I remove node_modules.

npm cache clean --force

npm install -D tailwindcss autoprefixer postcss

I uninstalled them and did the above commands but it keeps giving me above error. What is the relation of PostCSS to TailwindCSS why are both dependent on each other?

npx tailwindcss init

also it says

npm error could not determine executable to run npm error A complete log of this run can be found in: /home/amosmurmu/.npm/_logs/2025-01-23T15_39_50_870Z-debug-0.log

I also tried to change Node.js version using NVM but it gives structured clone error so its not Node.js or NPX or NPM.

Share Improve this question edited Jan 29 at 13:20 rozsazoltan 11.5k6 gold badges21 silver badges60 bronze badges asked Jan 24 at 8:40 amos murmuamos murmu 1331 gold badge2 silver badges8 bronze badges 3
  • 2 There are huge differences between TailwindCSS v3 and v4. Use npm install tailwindcss@3 to use v3. To migrate to v4, read the update guide in the documentation. The v4 was released a few days ago, so npm install tailwindcss now automatically installs v4 instead of v3. However, for this, you should no longer use the default Vite plugin, PostCSS and Autoprefixer: npm install tailwindcss @tailwindcss/vite - TailwindCSS v4 with Vite; TailwindCSS v4 with PostCSS – rozsazoltan Commented Jan 24 at 8:43
  • Using v3 should resolve all your issues. If you want to switch to v4, make sure to read the update and new installation guides. – rozsazoltan Commented Jan 24 at 8:47
  • 1 @rozsazoltan ok thank you – amos murmu Commented Jan 24 at 9:42
Add a comment  | 

2 Answers 2

Reset to default 24

TailwindCSS v3

The installation of TailwindCSS v3 and v4 is different. You were expecting the v3 installation, but v4 is the new latest version. For v3 installation, use:

npm install -D tailwindcss@3

Once this is done, the other steps remain unchanged:

  • Get started with Tailwind CSS - TailwindCSS v3 Docs

TailwindCSS v4

To install TailwindCSS v4, please refer to the updated installation and upgrade guides.

  • Get started with Tailwind CSS - TailwindCSS v4 Docs
  • Upgrading your Tailwind CSS projects from v3 to v4 - TailwindCSS v4 Docs

Some related question for v4 upgrade:

  • How to use TailwindCSS v4 & Vite without PostCSS
  • Separated PostCSS plugin for TailwindCSS
  • Removed @tailwind directives
  • Deprecated: Sass, Less and Stylus preprocessors support
  • Problem installing TailwindCSS with Vite, after "npx tailwindcss init -p" command
  • Error Installing Shadcn UI and Tailwind CSS in React.js Project with Vite
  • Automatic Source Detection from TailwindCSS v4

I see you're using v4. The use of tailwind.config.js has been removed, and instead, you can use a simple CSS-first configuration. However, it's possible to use the legacy JavaScript-based configuration via the @config directive.

  • New CSS-first configuration option in v4
  • TailwindCSS v4 is backwards compatible with v3

Delete the postcss.config.js file

And then npm i -d @tailwindcss/vite, and also change the vite.config.ts file

...
import tailwindcss from "@tailwindcss/vite";

export default defineConfig(async () => ({
  plugins: [
    react(),
    tailwindcss(),
  ],
...
...

then add @import "tailwindcss"; in your css file

转载请注明原文地址:http://anycun.com/QandA/1745153062a90398.html