next.js: Fails to Compile styled-components that use Props
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
I had a simple working styled-components header inside a Next@3 website:
h1 {
cursor: pointer;
${props => (props.primary && 'font-size: 6rem;') || 'font-size: 2rem;'}
line-height: 1.1;
margin-bottom: 1rem;
transform: skewY(-2deg);
}
This is based on the documentation for styled-components at: https://www.styled-components.com/docs/basics#adapting-based-on-props
Current Behavior
Upgrading to next@4 resulted in the following error message:
Module build failed: SyntaxError:
Found an `undefined` or invalid value in your styles: `props.primary`.
If you are trying to use dynamic styles in external files this is unfortunately not possible yet.
Please put the dynamic parts alongside the component. E.g.
<button>
<style jsx>{externalStylesReference}</style>
<style jsx>{`
button { background-color: ${props.primary} }
`}</style>
</button>
Steps to Reproduce (for bugs)
- Init a new Next@3 site with styled-components@latest, sample document, page and component: https://gist.github.com/jamiemchale/3d7d593f7911ad33b354a80f134b32fd
- Run, see site.
- Update to Next@4, run, see error.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 20 (2 by maintainers)
This issue should be fixed in
^4.0.2Btw I’ve had the same problem after updating, but strangely enough only with the SomeStyledComponent.extend`` syntax. For now I’m just working around that, but feels a little iffy, need to investigate more.
The following works for me using next 4
https://www.dropbox.com/s/c0k36b5gblqtbiq/Screenshot 2017-10-09 21.49.01.png?dl=0
@componentDidMount JFYI your username is funny, although it breaks search for the relevant issues
Same here! In addition to that I am also seeing:
Could be related?