styled-jsx: Error "insertRule` accepts only strings" when using with styled-components
What is the current behavior?
- Get
with-styled-componentsexample (https://github.com/zeit/next.js/tree/canary/examples/with-styled-components) - Add
<styled jsx tagto the index.js file so you got something like:
export default () => (
<div>
<h1>hello</h1>
<style jsx={true} global={true}>
{`
h1 {
color: red;
}
`}
</style>
</div>
)
- Error appears:
StyleSheet: `insertRule` accepts only strings.
- When i remove the
"styled-components"plugin from.babelrc, everything works fine.
What is the expected behavior?
Styled-jsx tags should work with styled-components + babel-plugin-styled-components in stack.
Environment (include versions)
- OS: OSX 10.13.4
- Browser: Chrome 70.0.3538.102
- styled-jsx (version):
3.1.0
Did this work in previous versions?
IIRC this was working in my older project with Next.js 6.1.1.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (3 by maintainers)
Commits related to this issue
- Shorten JSXStyle generated prop names. Fix #530 — committed to shYkiSto/styled-jsx by shYkiSto 6 years ago
- Shorten JSXStyle generated prop names. Fix #530 — committed to shYkiSto/styled-jsx by shYkiSto 6 years ago
I think I have found the cause.
babel-plugin-styled-components > 1.8.0can properly enable thecssprop of styled-components objects, whereas the same prop will be ignored inbabel-plugin-styled-components <= 1.8.0. Thecssprop then conflicts withstyled-jsxand cause the program to fail.@lucifer1004’s solution worked for me as well. Thanks 😃
we can switch from
to