最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Whenever I run my React-Vite it says [plugin:vite:esbuild] The service is no longer running - Stack Overflow

programmeradmin1浏览0评论

After running the npm run dev, it shows this:

[plugin:vite:esbuild] The service is no longer running

My config files are properly set up although I don't have a config file for PostCSS also.

vite.config.js

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/postcss';

// /config/
export default defineConfig({
  plugins: [
    react(),
    tailwindcss(),
  ],
})

I tried updating the esbuild but it's still the same.

After running the npm run dev, it shows this:

[plugin:vite:esbuild] The service is no longer running

My config files are properly set up although I don't have a config file for PostCSS also.

vite.config.js

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/postcss';

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react(),
    tailwindcss(),
  ],
})

I tried updating the esbuild but it's still the same.

Share edited Feb 11 at 13:51 rozsazoltan 9,2135 gold badges19 silver badges40 bronze badges asked Feb 11 at 10:11 Ayanfe TWEGAyanfe TWEG 211 silver badge1 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Solution #1: TailwindCSS v4 & Vite without PostCSS (recommended)

Since you're using Vite, you don't need PostCSS. TailwindCSS v4 provides a separate plugin for both Vite (@tailwindcss/vite) and PostCSS (@tailwindcss/postcss).

To inject TailwindCSS into Vite, you only need to install the following packages:

npm install tailwindcss @tailwindcss/vite

Then, modify the vite.config.js file as follows:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite' /* instead of @tailwindcss/postcss */

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react(),
    tailwindcss(),
  ],
})

After that, you just need to insert the import into your CSS file:

@import "tailwindcss";
  • Get Started TailwindCSS v4 with Vite - TailwindCSS v4 Docs

Solution #2: PostCSS & Vite with TailwindCSS v4

If you insist on using PostCSS, you only need to install the following packages:

npm install tailwindcss @tailwindcss/postcss postcss

After that, you need to associate PostCSS with Vite,

  • a.) modify the postcss.config.js file as follows:

    export default {
      plugins: {
        '@tailwindcss/postcss': {},
      },
    }
    

    Since Vite automatically uses PostCSS if a postcss.config.js file exists, you don't need to explicitly associate it with Vite. The installed TailwindCSS plugin will work accordingly.

    vite.config.file in this case:

    import { defineConfig } from 'vite'
    import react from '@vitejs/plugin-react'
    
    export default {
      plugins: [
        react(),
      ],
    }
    
  • b.) or modify the vite.config.js file as follows:

    import { defineConfig } from 'vite'
    import react from '@vitejs/plugin-react'
    
    export default defineConfig({
      plugins: [
        react(),
      ],
      css: {
        postcss: {
          plugins: {
            '@tailwindcss/postcss': {},
          },
        },
      },
    });
    

    For inline PostCSS config, it expects the same format as postcss.config.js. But for plugins property, only array format can be used.

    • css.postcss - Vite Docs

After that, you just need to insert the import into your CSS file:

@import "tailwindcss";
  • Get Started TailwindCSS v4 with PostCSS
  • css.transformer - Vite Docs

Some related information about TailwindCSS v4

  • Automatic Source Detection - StackOverflow
  • Deprecated: preprocessors support - StackOverflow
  • Removed @tailwind directives - StackOverflow
  • New CSS-first configuration instead of legacy JavaScript-based - StackOverflow
发布评论

评论列表(0)

  1. 暂无评论