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/

相关推荐
徐小夕29 分钟前
被CRUD拖垮的第5年,我用Cursor 一周"复仇":pxcharts-vue开源,一个全栈老兵的AI编程账本
前端·vue.js·github
Wect2 小时前
LeetCode 39. 组合总和:DFS回溯解法详解
前端·算法·typescript
Wect2 小时前
LeetCode 46. 全排列:深度解析+代码拆解
前端·算法·typescript
IT_陈寒2 小时前
Vite 凭什么比 Webpack 快50%?揭秘闪电构建背后的黑科技
前端·人工智能·后端
颜酱2 小时前
Dijkstra 算法:从 BFS 到带权最短路径
javascript·后端·算法
hi大雄3 小时前
我的 2025 —— 名为《开始的勇气》🌱
前端·年终总结
从文处安3 小时前
「前端何去何从」一直写 Vue ,为何要在 AI 时代去学 React?
前端·react.js
aircrushin3 小时前
OpenClaw“养龙虾”现象的社会技术学分析
前端·后端
明君879973 小时前
#Flutter 的官方Skills技能库
前端·flutter
yuki_uix4 小时前
重新认识 React Hooks:从会用到理解设计
前端·react.js