question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

5.0.0-4 existing postcss config does not work with new defaults

See original GitHub issue

Version

@nuxtjs/tailwindcss^5.0.0-4 “nuxt-edge”: “latest” “@nuxt/bridge”: “npm:@nuxt/bridge-edge”,

Steps to reproduce

I have the following existing postcss config in my project:

postcss: {
      plugins: {
        "postcss-nested": {},
        autoprefixer: {},
      },
    },

The resultant postcss config after the defaults are merged is as follows:

{                                                                                                                                                                                      
  'postcss-nesting': {},
  'postcss-custom-properties': {},
  tailwindcss: { }, // ... my config 
  'postcss-nested': {},
  autoprefixer: {},
}

I get Tailwind warning me that: “Nested CSS was detected, but CSS nesting has not been configured correctly. Please enable a CSS nesting plugin before Tailwind in your configuration. See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting

So I see a few issues here:

  1. Is there a way to turn off your default config (remove 'postcss-nesting': {}, 'postcss-custom-properties': {} and use postcss-nested ?

  2. How can I keep the plugin order correct to make sure Tailwind is happy with me?

I have a large codebase so refactoring all the css to use the nesting standard instead of the scss-compatible nested standard is not something I’m able to do right now.

I was struggling to get a codesandbox set up to show a reproduction - It kept crashing with 502 errors, so In left it. Hopefully the above info is enough to understand the issue. I can look further into a reproduction if necessary.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:9

github_iconTop GitHub Comments

8reactions
visualvalcommented, Mar 2, 2022

this worked for me

  build: {
    postcss: {
      order: ['tailwindcss/nesting', 'tailwindcss', 'autoprefixer'],
      plugins: {
        "postcss-nested": false
      }
    },
},
1reaction
jonathanjameswatsoncommented, Mar 10, 2022

As a temporary fix on Nuxt 3 with Vite you can add the following module:

import type { Plugin } from 'postcss'

import { defineNuxtModule } from '@nuxt/kit'

const order = (names: Plugin[]) => {
  const tailwindNesting = names.splice(
    names.findIndex((plugin) => plugin.postcssPlugin === 'tailwindcss/nesting'),
    1
  )[0]
  names.unshift(tailwindNesting)
}

export default defineNuxtModule({
  hooks: {
    'vite:extend'({ config }) {
      order(config.css.postcss.plugins)
    },
  },
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

5.0.0-4 existing postcss config does not work with new ...
I get Tailwind warning me that: "Nested CSS was detected, but CSS nesting has not been configured correctly. Please enable a CSS nesting ......
Read more >
Error: PostCSS plugin tailwindcss requires PostCSS 8
I tried to uninstall postcss and tailwindcss but it does not work. Need help. Module build failed (from ./node_modules/postcss-loader/src/index.
Read more >
postcss-cli | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
postcss-preset-env
CSS Spec: A Spec is a document that collects new features, what problems are they trying to solve and how it's intended to...
Read more >
Support any Browser with PostCSS & Babel
Because if JavaScript comes out with a new feature, we do not want to wait ... Copy that, go to the root of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found