There is a much easier way of achieving this and it doesn't require ejecting or any additional packages to be installed:
Instead of importing styled-components like this:
import styled from 'styled-components';
Import it like this:
import styled from 'styled-components/macro';
If that isn't working for you it is likely that you need to update styled-components or react. Further information can be found in the styled-components documentation.
Answer from Alex Mckay on Stack Overflowreactjs - Install babel-plugin-styled-components in create-react-app - Stack Overflow
Styled Components better debugging
I can't make class names readable created by styled components.
How use with Vite.js, especially displayName for debugging.
» npm install babel-plugin-styled-components
There is a much easier way of achieving this and it doesn't require ejecting or any additional packages to be installed:
Instead of importing styled-components like this:
import styled from 'styled-components';
Import it like this:
import styled from 'styled-components/macro';
If that isn't working for you it is likely that you need to update styled-components or react. Further information can be found in the styled-components documentation.
Create react app v2 has support for babel macros. There is a NPM package for styled-components macro. Just add the package to create react app and you are done.
yarn add styled-components.macro --dev
Doing this does not require eject of CRA.
#I solved this problem, thanks for helping.
##Thanks to redditors, I solved this problem by changing all "import from 'styled-components'" to ---> "import from 'styled-components/macro'"
----------------------------------------- my question was -------------------------------------------
1 - I added dependency --> "babel-plugin-styled-components": "^2.0.7"
2 - created a ".babelrc" file in root
3 - inside ".babelrc", I added -->
\``{`
"plugins": [
[
"babel-plugin-styled-components",
{
"fileName": true,
"displayName": true
}
]
]
} ```I tried above 3 steps and it still shows me gibberish classnames.
I tried --> stop development server and run it again with yarn start.
Got a next app with styled components wired up beautifully for SSR. However, when I import a package that uses styled components, the styles aren't getting picked up for the first paint for anything coming from that package. Anyone have experience with this?