question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lib with collection of styled-components work with console errors in next.js app. Related to babel config

See original GitHub issue

Please make sure you have read the submission guidelines before posting an issue

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation (nx.dev) and found no answer
  • I checked to make sure that this issue has not already been filed
  • I’m reporting the issue to the correct repository (not related to React, Angular or any dependency)

Expected Behaviour

I would expect the styled-components library to adopt the same babel config as the next.js application. Especially since the ssr option prevents the issue where className may change between server and client.

https://codesandbox.io/s/next-styled-components-working-y7r68

Current Behaviour

It is very noticeable that the classNames of the rendered components in dev mode do not include their file names and their display names

https://github.com/mcastro84/styled-components-issue

Failure Information (for bugs)

Often (admittedly, not all browser refreshes) will produce a console error

Warning: Prop `className` did not match. Server: "someClassName" Client: "someOtherClassName"

Steps to Reproduce

https://github.com/mcastro84/styled-components-issue

yarn start

Context

Please provide any relevant information about your setup:

We have multiple next.js apps in the nx monorepo and would like to share components between the two. We started off with styled-components before adopting next.js apps so we have a lot of legacy components that we would like to use

As you can see, I have implemented the code from the styled-components next.js example so that is not the issue: https://github.com/zeit/next.js/tree/canary/examples/with-styled-components

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jaysoocommented, Mar 3, 2021

A workaround is outlined here: https://github.com/nrwl/nx/issues/4611#issuecomment-788990096

The issue is that the root babel.config.json and additional babelrc files aren’t being picked up. This will be fixed in the next version, but you can use the workaround above for now.

0reactions
kirjaicommented, Mar 10, 2021

Fixed by #4944

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Next.js Compiler
js Compiler, written in Rust using SWC, allows Next.js to transform and minify your JavaScript code for production. This replaces Babel for individual...
Read more >
Tooling - styled-components
This plugin adds support for server-side rendering, minification of styles, and a nicer debugging experience. Usage. Install the babel-plugin first: npm install ...
Read more >
Warning: Prop `className` did not match. when using styled ...
You should install the babel plugin for styled-components and enable the plugin in your .babelrc ... I got an error when using material-ui...
Read more >
Using Styled Components - Expo Documentation
A guide for using Styled Components with Expo. ... you can create universal styles that'll work the same across web, mobile, ... babel.config.js...
Read more >
Setting up styled components with Next.js 9.5.2
Step 1 - Creating a Next.js application I just like all my development folders to be on... Tagged with nextjs, tutorial, styledcomponent, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found