文章目录
npx tailwindcss init报错 npm ERR! could not determine executable to run
我在配置好Tailwind4之后(具体配置见我的另一篇文章《在Vue3 + Vite 项目中使用 Tailwind CSS 4.0》),发现对比之前的版本少了taildwind.config.js
文件。于是,我想通过 npx tailwindcss init
新建这个文件。但是出现了报错。
报错详情:
npm ERR! could not determine executable to run
npm ERR! A complete log of this run can be found in: C:\Users\Administrator\AppData\Local\npm-cache\_logs\2025-02-16T04_11_16_774Z-debug-0.log
Tailwind4不再支持 taildwind.config.js
出现上文的问题在于 Tailwind4不再支持 taildwind.config.js
参考文章:https://github.com/tailwindlabs/tailwindcss/discussions/15820
找到官网中确实详细说明了:
官网地址 https://tailwindcss.com/blog/tailwindcss-v4#css-first-configuration
One of the biggest changes in Tailwind CSS v4.0 is the shift from configuring your project in JavaScript to configuring it in CSS.
Instead of a tailwind.config.js file, you can configure all of your customizations directly in the CSS file where you import Tailwind, giving you one less file to worry about in your project:
现在直接在css中@theme修改即可达到与 taildwind.config.js 相同的效果
还是在我之前文章中的 src\styles\index.css中添加下面所述代码: 《在Vue3 + Vite 项目中使用 Tailwind CSS 4.0》)
@import "tailwindcss";
@theme {
--color-mint-500: oklch(0.72 0.11 178);
--text-xs: 0.35rem;
}
- 在浏览器中就可以看到
--text-xs
这个值被修改成了我定义的 0.35rem而不是默认值
版本3的下载方法
$ npm install -D tailwindcss@3 postcss autoprefixer
$ npx tailwindcss init -p
参考文章:https://github.com/tailwindlabs/tailwindcss/discussions/15820