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 Overflow
🌐
GitHub
github.com › styled-components › babel-plugin-styled-components
GitHub - styled-components/babel-plugin-styled-components: Improve the debugging experience and add server-side rendering support to styled-components · GitHub
This plugin is a highly recommended supplement to the base styled-components library, offering some useful features:
Starred by 1.1K users
Forked by 142 users
Languages   JavaScript
🌐
styled-components
styled-components.com › docs › tooling
styled-components
It utilizes a babel helper to tag each styled component and library helper with the #__PURE__ JS comment that some minifiers use to overcome the aforementioned issue. This plugin transpiles styled-components tagged template literals down to a smaller representation than what Babel normally creates.
Discussions

reactjs - Install babel-plugin-styled-components in create-react-app - Stack Overflow
I am trying to use the styled-components-babel-plugin with a create-react-app application, to get the components name as classname in my chrome dev tools. But somehow, i do not get the classnames to More on stackoverflow.com
🌐 stackoverflow.com
Styled Components better debugging
I tried installing this babel plugin for a better css debugging experience with styled components. npm install --save-dev babel-plugin-styled-components { "plugins": ["babel-plugin-styled-components"] } However my styles should be something like instead of just . More on forums.meteor.com
🌐 forums.meteor.com
0
0
January 30, 2023
I can't make class names readable created by styled components.
Are you sure your builds are using Babel? Is your build tool (eg: Webpack) running Babel and is it referencing a Babel config that lives elsewhere? More on reddit.com
🌐 r/reactjs
4
5
May 10, 2022
How use with Vite.js, especially displayName for debugging.
When using with CRA, its possible to see name of component inside css classes, but I cannot figure out how to make a nice developing/debugging experience when using with Vite.js. Is there any advic... More on github.com
🌐 github.com
30
August 22, 2021
🌐
npm
npmjs.com › package › babel-plugin-styled-components
babel-plugin-styled-components - npm
This plugin is a highly recommended supplement to the base styled-components library, offering some useful features:
      » npm install babel-plugin-styled-components
    
🌐
Meteor
forums.meteor.com › help
Styled Components better debugging - help - Meteor Forum
January 30, 2023 - I tried installing this babel plugin for a better css debugging experience with styled components. npm install --save-dev babel-plugin-styled-components { "plugins": ["babel-plugin-styled-components"] } However my styles should be something like instead of just .
🌐
Reddit
reddit.com › r/reactjs › i can't make class names readable created by styled components.
r/reactjs on Reddit: I can't make class names readable created by styled components.
May 10, 2022 -

#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.

🌐
Medium
binyamin.medium.com › solving-the-styled-components-warning-in-next-js-with-babel-83080e45a0ff
Solving the Styled Components Warning in Next.JS with Babel | by Ben Grunfeld | Medium
April 14, 2021 - { "env": { "development": { "presets": ["next/babel"], "plugins": [ [ "babel-plugin-styled-components", { "ssr": true, "displayName": true, "preprocess": false } ] ] }, "production": { "plugins": [ [ "babel-plugin-styled-components", { "ssr": true, "displayName": true, "preprocess": false } ] ], "presets": ["next/babel"] }, "test": { "presets": ["next/babel"] } }, "plugins": [ [ "babel-plugin-styled-components", { "ssr": true, "displayName": true, "preprocess": false } ] ] } And that should do it!
Find elsewhere
🌐
GitHub
github.com › styled-components › babel-plugin-styled-components › issues › 350
How use with Vite.js, especially displayName for debugging. · Issue #350 · styled-components/babel-plugin-styled-components
August 22, 2021 - When using with CRA, its possible to see name of component inside css classes, but I cannot figure out how to make a nice developing/debugging experience when using with Vite.js. Is there any advices how to show in classes names of compo...
Author   valerii15298
🌐
my npm list
mynpmlist.yizack.com › package › babel-plugin-styled-components
Package: babel-plugin-styled-components | my npm list
List of users who have used babel-plugin-styled-components in their projects on GitHub and fetched them on this website.
🌐
Next.js
nextjs.org › docs › architecture › nextjs-compiler
Architecture: Next.js Compiler | Next.js
3 days ago - We're working to port babel-plugin-styled-components to the Next.js Compiler.
🌐
Markadamfoster
markadamfoster.com › styled-components-babel-macro
How to use the Styled Components Babel plugin with create-react-app | Mark Foster
Luckily, styled-components offers a Babel plugin to automatically add the React component display name to the generated classes (as well as in your React DevTools), which ends up looking like this:
🌐
Emotion
emotion.sh › docs › @emotion › babel-plugin
Emotion – @emotion/babel-plugin
const H1 = /*#__PURE__*/ styled('h1', { label: 'H1' })({ borderRadius: '50%', transition: 'transform 400ms ease-in-out', boxSizing: 'border-box', display: 'flex', ':hover': { transform: 'scale(1.2)' } }) ... This option assumes that you are using something to make @emotion/react's jsx function work for all jsx. If you are not doing so and you do not want such optimizations to occur, disable this option. This option allows you to tell @emotion/babel-plugin what imports it should look at to determine what it should transform so if you re-export Emotion's exports, you can still use the Babel transforms
🌐
npm
npmjs.com › package › @hookydev › babel-plugin-styled-components
@hookydev/babel-plugin-styled-components
May 16, 2020 - Easy package.json exports.. Latest version: 1.0.1, last published: 14 years ago. Start using package in your project by running `npm i package`. There are 280 other projects in the npm registry using package.
🌐
MUI
mui.com › material-ui › integrations › styled-components
Using styled-components - Material UI
As of late 2021, styled-components is not compatible with server-rendered Material UI projects. This is because babel-plugin-styled-components isn't able to work with the styled() utility inside @mui packages.
🌐
SourceForge
sourceforge.net › projects › babel-plugin-styled-com.mirror
babel-plugin-styled-components download | SourceForge.net
Download babel-plugin-styled-components for free. Improve the debugging experience and add server-side rendering support. This plugin is a highly recommended supplement to the base styled-components library, offering some useful features.
🌐
CodeSandbox
codesandbox.io › s › babel-plugin-styled-components-iueny
babel-plugin-styled-components - CodeSandbox
June 3, 2020 - babel-plugin-styled-components by baybara-pavel using babel-plugin-styled-components, react, react-dom, react-scripts, styled-components, typescript-plugin-styled-components
Published   Nov 26, 2019
Author   baybara-pavel
🌐
Sheelah Brennan
sheelahb.com › blog › styled-components-with-create-react-app
How to Use the styled-components Babel Plugin with Create React App | Sheelah Brennan
December 5, 2018 - Confirm that the Babel plugin is working: Using your browser's dev tools (no React dev tools extension needed), inspect your React component and check that you can see the component's styled-component name and CSS classes, not just the CSS classes themselves.