5

(4:3) 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

My postcss.config.js file:

  plugins: [
    "postcss-import",
    "tailwindcss/nesting",
    "tailwindcss",
    "autoprefixer",
  ],
};

I tried to write it down like this:

  plugins: {
    "postcss-import": {},
    "tailwindcss/nesting": {},
    tailwindcss: {},
    autoprefixer: {},
  },
};

and like this:

  plugins: [
    require("postcss-import"),
    require("tailwindcss/nesting"),
    require("tailwindcss"),
    require("autoprefixer"),
  ],
};

Github repo with this project: https://github.com/frkam/test-app

When I try to use nesting, i get this:enter image description here

3
  • Are you using Create React App, version 5? There are some known issues with PostCSS support, which is now included along with Tailwind, and CRA 5 does not allow overrides using postcss.config.js. See: github.com/facebook/create-react-app/pull/… Commented Jan 31, 2022 at 16:23
  • @EdLucas yes, i use CRA5. As I understand it, the solution to this problem may be to roll back to a previous version or use a different preprocessor. Thanks. Commented Jan 31, 2022 at 17:37
  • 1
    There's an open PR to fix this, which will hopefully be implemented. You can follow the issue here: github.com/tailwindlabs/tailwindcss/discussions/7049 Commented Feb 5, 2022 at 17:48

1 Answer 1

3

As Ed Lucas mentioned above CRA5 does not allow to override postcss.config But at the moment you can use something like craco

An Example you can find in Felipe Zavan comment

This works for me. So I hope it will be helpful :)

My craco.config

module.exports = {
  style: {
    postcss: {
      loaderOptions: (postcssLoaderOptions) => {
        postcssLoaderOptions.postcssOptions.plugins = [
          require('tailwindcss/nesting'),
          require('tailwindcss'),
          require('postcss-mixins'),
          'postcss-flexbugs-fixes',
          [
            'postcss-preset-env',
            {
              autoprefixer: {
                flexbox: 'no-2009',
              },
              stage: 0,
            },
          ],
        ]

        return postcssLoaderOptions
      },
    },
  },
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.