Problem with installing Sanity CMS for NextJS with Tailwindcss, solution found in a different guide.

17 replies
Last updated: Dec 15, 2022
πŸ‘‹ Hello, team! I have a problem with installing Sanity CMS for NextJS with Tailwindcss. I followed the guide https://www.sanity.io/guides/sanity-nextjs-tailwindcss . Sanity works well, before I install Tailwind, after I install Tailwind I get the error in the attached screenshot. Is there a solution for this or am I doing something wrong?
AI Update

I can see you're running into an issue after installing Tailwind CSS in your Next.js + Sanity project! While I couldn't see the screenshot you mentioned, this is a very common problem and I can help you solve it.

The issue you're experiencing is likely the "Unknown at rule @tailwind" error appearing in your Sanity Studio. This happens because when you install Tailwind CSS in your Next.js project, it creates a global postcss.config.js file that affects both your Next.js app AND your Sanity Studio (which lives in the /studio folder).

The Solution

The guide you followed was written for Studio v2, which is now deprecated. But more importantly, Sanity Studio has its own build configuration and doesn't need Tailwind CSS. The error occurs because your global PostCSS config is trying to process Studio files with Tailwind directives they don't understand.

Here are two ways to fix this:

Instead of having a global postcss.config.js in your root, create it inside your Next.js-specific directories or use a more targeted approach:

  1. Delete the root postcss.config.js file
  2. Create postcss.config.mjs in your root with this content:
export default {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}
  1. Make sure your tailwind.config.js excludes the studio folder:
module.exports = {
  content: [
    './pages/**/*.{js,ts,jsx,tsx,mdx}',
    './components/**/*.{js,ts,jsx,tsx,mdx}',
    './app/**/*.{js,ts,jsx,tsx,mdx}',
    // Make sure NOT to include './studio/**/*'
  ],
  // ... rest of config
}

Option 2: Add PostCSS Config to Studio

If the above doesn't work, create a separate postcss.config.js inside your /studio folder:

// studio/postcss.config.js
module.exports = {
  plugins: {
    // Empty or Studio-specific plugins only
  },
}

This tells the Studio to use its own PostCSS configuration instead of inheriting from the root.

Additional Tips

  • Consider upgrading to Studio v3 - The guide you followed is for the deprecated Studio v2. Studio v3 has better separation and fewer conflicts with Next.js tooling. It also requires Node.js 20+ and has improved architecture.

  • Check your import paths - Make sure you're only importing your Tailwind CSS file (tailwind.css or similar) in your Next.js _app.js, NOT anywhere in the Studio code.

  • Restart both dev servers - After making these changes, restart both yarn dev (Next.js) and yarn sanity (Studio) to ensure the configs are properly loaded.

The key principle here is that Sanity Studio and your Next.js app are separate applications that happen to live in the same repository. They each need their own build configurations, and Tailwind should only be configured for your Next.js frontend, not the Studio.

Let me know if you're still seeing issues after trying these solutions!

Note that this is a V2 project and quite old
Hi Harald, thanks for replaying that quick! Yes I noticed that it is a guide from V2. I will try the guide you just posted. Thanks
try this instead. This fit your purpose a lot better. Using NextJS, tailwindCSS and Sanity. and help you with deploying a vercel link!
Great! Thank you very much! I will look in on it directly πŸ™
No worries!
Damn! I’m the one who wrote that guide, and sorry for that πŸ™‚
I’m gonna write a new one for v3 + next 13 soon!
user E
In the meantime, just clone this repo and you are good to go: https://github.com/surjithctly/jamstack-starter
It uses Sanity v3, Next 13 (appDir) and TailwindCSS
Thank you Surjith πŸ™
user H
I cloned your repo and tried to run it, but unfortunately, it doesnt work
user H
user E
I have the same problem, trying to figure out what I'm doing wrong for a while now. If you find a solution, can you please share it with me. πŸ˜‰
user U
user E
That works perfect and good explained! Thank you very much! To bad wasted my time, thanks again!
user U
user E
That works perfect and good explained, thanks again!
user E
user E
what error do you get? can you share screenshot? I have it working on my local without any problem.

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?