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/

相关推荐
恋猫de小郭2 小时前
Flutter 状态管理基准测评,一个很有趣的观点
android·前端·flutter
西西弗Sisyphus2 小时前
Qt 实现一个 Windows 启动项查看器
开发语言·windows·qt
FfHUCisI2 小时前
Golang 函数调用的瞬间:栈帧、拷贝栈与逃逸分析
开发语言·后端·golang
雪芽蓝域zzs2 小时前
前端编辑组件wangEditor
前端
万邦科技Lafite2 小时前
淘宝海外采购指南,taoworld资格申请对接流程讲解
开发语言·电商开放平台·淘宝开放平台·京东开放平台·比价
ThornArmor2 小时前
奔腾的呼吸:被驱逐者的灵感
开发语言·程序人生·架构
软件黑马王子2 小时前
12.缓存池优化:对象上限
开发语言·前端框架·c#
阿里嘎多学长2 小时前
2026-09-07 GitHub 热点项目精选
开发语言·程序员·github·代码托管
风骏时光牛马2 小时前
稳定性治理及疑难问题深度剖析与实战复盘
前端
AIGC小尼2 小时前
穿山甲 + 腾讯短剧短视频聚合广告平台|Android+SpringBoot+Vue+Docker 完整部署指南
android·vue.js·spring boot·聚合广告·广告平台·穿山甲广告·腾讯广告