-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Styling custom components with NextJs #447
Comments
But it works if i pass anonymous function:
|
Do you have a |
yes
like in this example https://github.com/zeit/next.js/tree/canary/examples/with-linaria |
Yeah, this has been a big headache trying to port from styled-components. I believe it might be a result of using the wrong babel bundling strategy (module: true vs module: false). |
@talentlessguy, check the README again. Linaria definitely does work with Next if you set up everything correctly. If you're sure your config is correct, then you should create a new issue. This thread is for a different problem. |
I also stumbled across this problem and found out that applying styled on an already transpired/bundled Component from a dependency, everything works fine.
This doesn't throw an error since it's already transpired. There must be a problem with Next config that breaks Babel transpilation |
It's probably not helpful, but just confirming this still occurs with the latest version of Next + Linaria's latest beta. I'm not smart enough to figure out how to fix this. |
I have linaria babel plugin installed:
|
@talentlessguy you've also got to update your next.config.js. Look through all the files here and see if you're missing anything else. https://github.com/zeit/next.js/tree/master/examples/with-linaria |
@mikestopcontinues hm ok it works now but only with |
Anyone able to get Linaria working with CSS modules and Next.js? |
It works perfectly for me just following the readme and example I posted above. @Pytal |
The above comments are a little bit confusing and a diversion from the purpose of this issue. The Next.js example is still broken when wrapping a React component with styled, as seen at https://codesandbox.io/embed/hello-world-bu9q8 The following pattern does not work function Component(props) { return <div {…props}>Hello</div> }
const StyledComponent = styled(Component)`color: red` This fails to compile:
This is still an issue and seems to be something to do with the way Webpack or Babel are configured in the example. |
I think the problem is between A workaround is removing your
This solves the issue. |
@fernandojbf, that's a great short-term solution, and I'm grateful for it. Though next may update to include other crucial config in their preset. We shouldn't plan against it. There must be something fixable about next's preset or linaria's preset to ensure the problem doesn't come back. |
@mikestopcontinues yes, this was intended to be short-term solution. I've tested some configurations on the |
It would be awesome to support next.js. If there is a real issue with configs we should solve it or write better docs on how to integrate those two projects. I will put it on my list to check what's exactly going on. |
I ran into this one today with the set-up detailed in the next.js example config mentioned above. Messing around with https://github.com/zeit/next.js/blob/v9.3.5/packages/next/build/babel/preset.ts#L130 It starts to break again once they're both set to the same name, though. Note that it doesn't matter what you set the option to, as long as they're both the same (so it isn't any special handling on the name itself but what it's doing - setting both Diving deeper, their
I can't tell anything more, though (would need to dive a lot more into how Babel traverses the AST and where, when, and how Linaria comes into play here), though I do know the issue occurs when the plugin is modifying files via This would explain why #447 (comment) works: you're removing this plugin entirely. I'm not sure about what |
Thanks @twolettername, your research really helps to understand what causes the issue. During the evaluation, we cannot have any The problem is this However, the issue will be solved in Linaria For now, to fix it, you should use the lastest Linaria beta for
It enables mentioned |
Next.js example fixed: vercel/next.js#13568 :) |
For me, this library works well |
The issue is still present. Just as it described in the first message. I found a solution in this emotion.js issue they had the same problem.
and installing @babel/preset-env as it asked:
Hope it'll help someone :) |
I'm using NextJs with linaria and trying to apply styled on custom component:
and get error:
The text was updated successfully, but these errors were encountered: