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

laravel - Loading PostCSS Plugin failed: Cannot find module 'tailwindcss' error when I run using vite - Stack Ov

programmeradmin1浏览0评论

When I run this project using npm run dev, then my output errors:

[vite] Internal server error: Failed to load PostCSS config

Error: Cannot find module 'tailwindcss'

Here are the contents of postcss.config.js:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};

How can I solve this?

When I run this project using npm run dev, then my output errors:

[vite] Internal server error: Failed to load PostCSS config

Error: Cannot find module 'tailwindcss'

Here are the contents of postcss.config.js:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};

How can I solve this?

Share Improve this question edited Feb 5 at 14:53 rozsazoltan 7,8685 gold badges17 silver badges38 bronze badges asked Feb 5 at 13:51 Iim Abdul KarimIim Abdul Karim 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Separated PostCSS plugin for TailwindCSS

In v3, the tailwindcss package was a PostCSS plugin, but in v4 the PostCSS plugin lives in a dedicated @tailwindcss/postcss package.

Starting from v4, the @tailwindcss/postcss plugin has been separated from the TailwindCSS package, as it is not needed by everyone. You need to install this separate plugin and reference it from v4 to load TailwindCSS through PostCSS, like this:

npm install tailwindcss @tailwindcss/postcss postcss

postcss.config.mjs

export default {
  plugins: {
    "@tailwindcss/postcss": {},
  }
}
  • Get Start TailwindCSS using PostCSS - TailwindCSS v4 Docs
  • Upgrade guide: Using PostCSS

Deprecated PostCSS plugins from TailwindCSS v4 onwards

Additionally, in v4 imports and vendor prefixing is now handled for you automatically, so you can remove postcss-import and autoprefixer if they are in your project.

Thanks to the structure of this separate plugin, you no longer need to use the autoprefixer and postcss-import packages.

npm uninstall autoprefixer postcss-import

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论