tailwindcss: .container plugin not working out of the box

The “container” plugin that ships with Tailwind doesn’t seem to be working for me.

my tailwind.js file:

 plugins: [
    require('tailwindcss/plugins/container')({
      center: true,
      padding: '1rem',
    }),
  ]

my mix file:

mix.js('resources/assets/js/app.js', 'public/js')
    .postCss('resources/assets/css/app.css', 'public/css')
    .tailwind()

I can verify that my tailwind.js file is being used (by switching color values and seeing them reflected)

I’m on 0.5.2

A co-worker set up a brand new tailwind project and verified the same issue.

This could very well be PEBCAK, but I’m kinda out of ideas.

If you don’t quickly identify this as an actual bug I will dig deeper, just want to make sure this isn’t currently an issue effecting everyone.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 18 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Do you have @tailwind components in your CSS file? On Wed, Apr 4, 2018 at 5:28 PM nordentwickler notifications@github.com wrote:

Same on here, updated from 0.4 to 0.5.2 and the container plugin is not working.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tailwindcss/tailwindcss/issues/446#issuecomment-378751221, or mute the thread https://github.com/notifications/unsubscribe-auth/AEH3bEodEFsYlb__tutciWJNIqKblqgAks5tlTsQgaJpZM4THhAk .

Can you share the actual code that’s throwing the error? Sounds like maybe you are using a Babel macro or some other non-official thing?

Hi @adamwathan, Indeed it seems related to tailwind.macro. I’m having the same issue using styled-components and tailwind. The workaround I found for now was to add the container class directly to my styled component.

Screenshot 2020-01-01 17 17 57

import React from "react"
import styled from 'styled-components'
import tw from 'tailwind.macro';

const Main = styled.main`
  ${tw`w-full flex flex-wrap mx-auto container`}; <- with container throw an error
  ${tw`w-full flex flex-wrap mx-auto`}; <- without container doesn't throw an error

const Layout = ({ children }) => {
  <>
    <Main className="container">{children}</Main> <- workaround add the container class directly on the component
  </>
}

export default Layout

@SimonJ Make sure that @tailwind components; is behind @tailwind utilities; in your css file.

Attempting to use Tailwind 1.1.3 with Gatsby and Emotion. The container class throws an error. Error: “Couldn’t resolve Tailwind class name: container”

Yes I have included @tailwind base;

@tailwind components;

@tailwind utilities;

in global.css

Same problem here. Gatsby, Emotion, Babel, PostCss. For files, see below. I don’t know if it is emotion at fault… when I avoid using emotion and just throw a container class into a JSX div:

<div className="pt-24 container">

…when I mouse over the pt-24 style in VSS, the style resolves, but container does not.

Some details:

style.css

@tailwind base;
@tailwind components;
@tailwind utilities;

...

tailwind.config.js

module.exports = {
  theme: {
    fontFamily: {
...
    },
    extend: {
      colors: {
...
        }
      }
    }
  },
  variants: {},
  plugins: []
};

babel-plugin-macros-config.js

module.exports = {
  tailwind: {
    styled: `@emotion/styled`,
    config: `./tailwind.config.js`,
    format: `auto`,
  },
}

postcss.config.js

const tailwindcss = require(`tailwindcss`);

module.exports = {
  plugins: [
    tailwindcss(`./tailwind.config.js`),
    require(`autoprefixer`),
    require(`cssnano`)({
      preset: `default`
    })
  ]
};

This tripped me up as well. One place where it could be mentioned is in the container section in the docs: https://tailwindcss.com/docs/container – I remember seeing the @tailwind components directive while installing but not thinking I was using any plugins (i.e. this was a clean Tailwind installation), I ignored and forgot it.

@tailwind components

It would be nice to add this to the docs 😃

Maybe it’s worth to add on the docs which part related to what tailwind package (utilities/base/components)