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.

Styled components not working with Gatsby. Reproducible.

See original GitHub issue

Description

It seems like Gatsby is not adding styled component’s styles to the DOM. SC is correctly adding the classes to the DOM elements and you can even see them change dynamically, but nothing is styled correctly.

What is very weird is that I got it to work by deleting by code and then copy-pasting it again (they were no more than 10 lines of code). However, it stopped working after refreshing and I couldn’t get it to work ever again.

Steps to reproduce

Install gatsby following the “Get started” steps:

gatsby new gatsby-site

Then follow the steps on Gatsby with Styled Components.

Run the project:

npm run develop

Try to use a styled component > nothing happens.

You can see a very minimal repo with nothing more than the gatsby installation and styled-components added to it.

Repo here

Expected result

Styled components should work as expected.

Actual result

Styled components don’t work.

Environment

System: OS: macOS 10.15.1 CPU: (16) x64 Intel® Core™ i9-9880H CPU @ 2.30GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.16.3 - ~/.asdf/installs/nodejs/10.16.3/bin/node Yarn: 1.17.3 - /usr/local/bin/yarn npm: 6.9.0 - ~/.asdf/installs/nodejs/10.16.3/bin/npm Languages: Python: 2.7.16 - /usr/local/bin/python Browsers: Chrome: 78.0.3904.108 Firefox: 71.0 Safari: 13.0.3 npmPackages: gatsby: ^2.18.8 => 2.18.8 gatsby-image: ^2.2.34 => 2.2.34 gatsby-plugin-manifest: ^2.2.31 => 2.2.31 gatsby-plugin-offline: ^3.0.27 => 3.0.27 gatsby-plugin-react-helmet: ^3.1.16 => 3.1.16 gatsby-plugin-sharp: ^2.3.5 => 2.3.5 gatsby-plugin-styled-components: ^3.1.16 => 3.1.16 gatsby-source-filesystem: ^2.1.40 => 2.1.40 gatsby-transformer-sharp: ^2.3.7 => 2.3.7 npmGlobalPackages: gatsby: 2.18.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
obedparlacommented, Dec 16, 2019

Ok wtf I located the issue after realizing that it worked on Chrome incognito but not on my normal window even after clearing the cache.

the issue was due to the Chrome extension “Loom”. I have no idea why. I’m using SC in several other projects with a similar setup (Webpack, Babel, etc) with no issues.

Anyway, closing this issue. If you land here, verify whether SC runs on an incognito window and if it does, check your extensions ¯_(ツ)_/¯

2reactions
obedparlacommented, Sep 22, 2020

if I recall correctly, it was working on prod (build). The issue was only on dev

Read more comments on GitHub >

github_iconTop Results From Across the Web

I finally fixed my Styled-Components in gatsby.js
The fix. The fix was so simple it was only 2 lines total. One to install gatsby-plugin-styled-components and one to use it.
Read more >
Gatsby - Nestled Component Not Rendered - Stack Overflow
The problem you are facing here is that your Tile component is inside the /pages folder as you pointed here: Tile.js (within the...
Read more >
Gatsby Style Guide
Answer: Developers with knowledge and experience coding in HTML, CSS, and JS but not necessarily React or GraphQL. Question: What do I hope...
Read more >
gatsby-plugin-styled-components - npm
A Gatsby plugin for styled-components with built-in server-side rendering support. Install. npm install gatsby-plugin-styled-components styled- ...
Read more >
Fixing styled-components server-side-rendering issues in ...
1. Check you have gatsby-styled-components & babel-plugin-styled-components ` installed. · 2. Check that each css property ends with a semicolon ...
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