vue3使用tailwindcss报错问题

  1. npm create vite@latest

  2. npm install -D tailwindcss postcss autoprefixer

  3. npx tailwindcss init
    4. ·不过执行 npx tailwindcss init 的时候控制台就报错了

    js 复制代码
    PS E:\vite-demo> npx tailwindcss init
    npm ERR! cb.apply is not a function
    npm ERR! A complete log of this run can be found in:
    1. 那就手动创建 tailwind.config.js文件和postcss.config.js文件
    js 复制代码
    	// tailwind.config.js
    	/** @type {import('tailwindcss').Config} */
    	module.exports = {
    	  content: ["./src/**/*.{html,js}"],
    	  theme: {
    	    extend: {},
    	  },
    	  plugins: [],
    	}
    js 复制代码
    // postcss.config.js
    module.exports = {
      plugins: {
        tailwindcss: {},
        autoprefixer: {},
      }
    }

    然后再style.css引入

    css 复制代码
    @tailwind base;
    @tailwind components;
    @tailwind utilities;

    npm install
    报错

    js 复制代码
    [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.
  4. 重新安装 npm install @tailwindcss/postcss

js 复制代码
	import postcssTailwind from '@tailwindcss/postcss'; 
		import autoprefixer from 'autoprefixer'; 
		export default { 
		    plugins: [ postcssTailwind, autoprefixer ]
		};

注意: 要看清版本 现在安装的tailwindcss 是4.x 官网是3.x

地址:https://tailwindcss.com/

相关推荐
foo1st1 分钟前
HTML中常用HASH算法使用笔记
javascript·html·哈希算法
3824278272 分钟前
python3网络爬虫开发实战 第二版:绑定回调
开发语言·数据库·python
星月心城8 分钟前
面试八股文-JavaScript(第五天)
开发语言·javascript·ecmascript
小白x8 分钟前
Echarts常用配置
前端
hello_Code11 分钟前
css和图片主题色“提取”
前端
小杨梅君11 分钟前
Vue3与iframe通信方案详解:本地与跨域场景
前端·vue.js
wjs202412 分钟前
PostgreSQL 时间/日期处理指南
开发语言
IT_陈寒13 分钟前
Redis高频踩坑实录:5个不报错但会导致性能腰斩的'隐秘'配置项
前端·人工智能·后端
CoolerWu16 分钟前
2025 · 我与 AI / Vibe Coding 的一年
前端·后端
wniuniu_17 分钟前
ceph心跳机制
开发语言·ceph·php