babel-plugin-styled-components icon indicating copy to clipboard operation
babel-plugin-styled-components copied to clipboard

css prop stopped working in [email protected]

Open Lwdthe1 opened this issue 4 years ago • 2 comments

I have been using the css prop to style my components since nextjs@10.2.0 (also tested at @10.2.3, the latest version before 11.0.0). It's been working wonderfully.

When I upgrade nextjs to 11.0.0, the css props is no longer compiled; the template string is just rendered as is.

<div css={css`background: red`}>...</div>

// becomes
<div css="background: red">...</div>

That means no styling from the css prop is applied to the element as desired.

This is the only console error log when I refresh the page: Screen Shot 2021-08-21 at 1 02 19 PM

But even when I resolve that error, the problem at hand remains.

Using the styled.div approach still works, though.

Lwdthe1 avatar Aug 21 '21 16:08 Lwdthe1

Have you removed your babel.config.json or .babelrc? Because if you did, you moved to SWC instead of Babel. The css prop of styled-components isn't supported yet for SWC.

Adding a config for babel will likely resolve your issue: https://styled-components.com/docs/tooling#babel-plugin

simon-debruijn avatar Mar 01 '22 12:03 simon-debruijn

Thanks for those links. Looks like this may have been resolved in NextJS 12.2.0 https://github.com/vercel/next.js/releases/tag/v12.2.0

Lwdthe1 avatar Aug 21 '23 22:08 Lwdthe1