Error using babel plugins for CSS (ie. babel-plugin-styled-components)
See original GitHub issueHi,
I’m trying to use styled-components to manage my CSS. I need SSR take into account CSS too and because of this I have created a .babelrc
file with:
{
"plugins": [
"styled-components"
]
}
My page index.js
is as simple as:
const App = ({ children, title = '' }) => (
<div>
<Head>
<title>{ title }</title>
<meta charSet='utf-8' />
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
<link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500' rel='stylesheet' />
</Head>
<header>
<nav>
<Link href='/'><a>Home</a></Link> |
<Link href='/about'><a>About</a></Link> |
<Link href='/contact'><a>Contact</a></Link>
</nav>
</header>
<Zone>
{ children }
</Zone>
<footer>
Footer
</footer>
</div>
)
export default () => (
<App>
Nothing to show
</App>
)
But I’m getting next error when the page is compiled
ERROR Failed to compile with 1 errors 6:55:53 PM
error in ./pages?entry
Syntax Error: Unexpected token (11:2)
9 |
10 | const App = ({ children, title = '' }) => (
> 11 | <div>
| ^
12 | <Head>
13 | <title>{ title }</title>
14 | <meta charSet='utf-8' />
In addition, as an alternative, I have tried to use css-modules with babel-plugin-react-css-modules
but same error in the same place is thrown.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Nothing transformed (usage with webpack and typescript) #19
I tried to use the plugin together with webpack (babel-loader) and ... no error but the plugin shows no effect, i.e. the CSS...
Read more >babel-plugin-styled-components not working - Stack Overflow
I've been trying to get the babel-plugin-styled-components plugin to work with my webpack/babelrc configuration but I have not been able to ...
Read more >babel-plugin-styled-components - npm
Start using babel-plugin-styled-components in your project by running `npm i babel-plugin-styled-components`. There are 1122 other projects ...
Read more >babel-loader - webpack
This package allows transpiling JavaScript files using Babel and webpack. Note: Issues with the output should be reported on the Babel Issues tracker....
Read more >Stop using CSS in JavaScript for web development
CSS isn't going anywhere. A lot of the projects choose to style documents in JavaScript for wrong reasons. This article lists common misconceptions...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You need to add
to
.babelrc
(see this).@acanimal and @coliverav89 If youre seeing: Uncaught TypeError: _styledComponents2.default.div.withConfig is not a function
Make sure your using v2 of styled-components. Refer to this github issue: https://github.com/styled-components/babel-plugin-styled-components/issues/43#issuecomment-293350554