-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS styles do not load after deploying to Surge or Netlify #5100
Comments
Do your styles get created locally? |
@KyleAMathews could this be another case not configuring html.js properly as in #4754 ? |
@KyleAMathews I did a @ajayns What am I looking for in html.js? When I followed your link, I did come across this issue but what I am changing? Am I declaring |
Could this be related to #4418? |
This morning I read into @ajayns link and got an idea of inserting a link tag with href pointing to my styles.css in the same folder. I inserted it in my index file in the |
I found a fix for my site. To fix the issue, I applied the global on my top level styled component. |
@zacaytion I did compare my a previous commit before I added my changes and that works in Netlify. Though, I'm having a hard time finding what I did in that previous commit which made it work. |
Update I tried every trick and suggestion on this issue. None of them are working. Is there something special on a linux machine I have to do to get this working? I looked at a previous version I did and it works Thanks, I'm at my wits end here. |
Linux is case sensitive for filenames so probably you're importing a component that's e.g. uppercase and typing it as lower case which works on Mac but won't on Linux. |
@KyleAMathews I tried a workaround. Instead having Gatsby doing the sass compling, I ran the sass complier in the command line and imported the complied css in my index layout. It's working on Netlify. Although, I really want to understand why this is happening on under the hood. I'll start looking the dev version of Gatsby. |
I can confirm after 4 hours of trying to figure out the same problem that it was a capitalization problem that was preventing Netlify from inserting the inline styles. That was a frustrating problem, but I am glad I found this thread! I almost gave up! |
@themostcolm What was the capitalization problem you discovered? I am in the same exact situation as all of you and I'm completely stuck and have tried all of the things mentioned in the GitHub issues. |
@drake-smith Sure! I use stylus, so in my import statement I had @import '../layouts/Header/header.styl' when my actual file layout was src/layouts/Header/Header.styl. It worked perfectly in development, but did not work on Netlify. Also make sure if you are using git that you have the correct capitalization in your git repository. Sometimes if you change the capitalization of the file, git doesn’t recognize that at all. You can do this with: git mv oldFileName newFileName |
@themostcolm Thank you! @DanStockham Could you walk through what steps you took for your Sass compile workaround? I've discovered the same issue in that my Sass doesn't compile in a Linux environment (Netlify). You're running sass in command line, and removing any webpack Sass commands from gatsby-config? |
I've also found same issue with my site & it isn't loading CSS on first load as you can check. And I'm using Emotion. Any solutions @KyleAMathews ❓ Solutions mentioned here don't work for me sadly :( |
I've got it. I opened up a new issue #6406 |
@deadcoder0904 did you solve the issue? I'm facing the same problem. On first load it doesn't load all the styles but on visiting some other page via some internal links on the page it applies all the styling. I'm using styled-system and rebass for styling so i don't have any external sass files. Note: Everything was working fine with Gatsby@1. Thanks in advance! |
@rishichawda I don't remember what I did to solve it but I think everything must use That might be the solution. Everything is working fine now for me :) |
@deadcoder0904 I had updated all the plugins to use |
I checked those 3 you mentioned & it looks good so I think you are definitely missing something. Can't help it unless there is something specific. I remember now that my error was I wasn't using v2 of emotion gatsby plugin & I think I had to clear Netlify cache since I was using https://github.com/axe312ger/gatsby-plugin-netlify-cache which uses previous cache to speed up deployment. So those 2 were my problems. I think you will find answer if there is something relevant you can post or else you checkout example sites made using rebase & styled-system. I did it that way. Sorry I don't have a solution for you :( |
No problem! Thanks for sharing. I'm waiting for the issue to be fixed ( hopefully ) in future updates of gatsbyv2. |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub issues, we have to clean some of the old issues as many of them have already been resolved with the latest updates. Please make sure to update to the latest Gatsby version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 |
I just ran into this today. I built the site with Gatsby v2 but my css is not being applied on initial load. I've looked at the solutions linked here but no luck so far. I'm using emotion. I have another site that I updated from Gatsby v1 and that site is using styled components without any issues? |
Having the same issue. My git repo is here: https://bitbucket.org/maxmatthews/codecommunity and my site is https://codecommunity.io But as soon as I run The interesting thing is if you go to any other page like https://codecommunity.io/thanks and then click on a link to the homepage, it renders the CSS fine. Have to be missing something here... |
I have the same problem as @maxmatthews. I found several issues related to this with no definitive fix. |
I'm also using styled components. This was fixed for me as soon as I added the Gatsby styled-components plugin to my build, using the steps outlined here: https://www.gatsbyjs.org/docs/styled-components/ Before fixing this, my styles wouldn't load on my first page load, until I navigated to another route. Now everything loads the first time. |
After reading everything I could find, contacting Netlify, and struggling with removing service workers per their advice, I decide to start over and slowly rebuilt my site to see what it could possibly be. I did install the plugins correctly so i was good on that end. My confusion is primarily that styling was applied correctly in development but in production could only be (inconsistently) forced to apply by redirecting manually to another page. After rebuilding the site there are slight differences with how I used the layout component making direct comparison impossible. One other difference is that I went with styled-components vs emotion. Everything works as expected now. I have since begun adding media queries and did notice that if I used more complex queries I had similar behavior but with no way to force the actual styles to be applied. Enough to get me thinking this is related but not the same issue. After cleaning up my queries, there are no issues. |
I wanted to chime in to say that I'm having the exact same issue. Using Gatsby v2, using Emotion. All is good in dev, but once built there are no styles being displayed unless following an internal link. Working on trying to fix it now. Update: Just switched entire project over to styled-components. Didn't do anything. Then I tried going back to the dev server, and I was getting the same issue. So I went back to a known good version of the repo (with Emotion) and tried the dev server and it worked. So I tried building it and it worked. So I don't know exactly what I did wrong but I clearly messed something up. Between the known good version and the no-style version, I added proptypes and I might have changed a few little things here and there, but not enough that it would ruin it in the way that it did. So I'm really not sure what the issue was. Maybe I'll go back over when I've slept and it'll be obvious. |
@justinformentin Did you try adding 'gatsby-plugin-emotion' to your gatsby-config.js? I had exactly the same issue like you (not emotion, but styled-component), after I added 'gatsby-plugin-styled-components' (according to @liamdanielduffy's comment) in the plugins config, the production build worked as normal. If this is a common issue, it might worth adding warning message in dev mode. |
We are running into a similar issue but what we were seeing was only a single component was not having the styles applied to it until navigating to another page and back. We are using all the very latest packages and plugins. We are currently using I was doing some troubleshooting and found that if I moved the component experiencing the issue further up in the tree of its parent, more components were being affected by missing styles. I ended up finding a fix for the issue we were experiencing. The component which wasn't getting the styles applied to it right away has a Additional Info: The component having the issue has a default state of if (!this.state.showBanner) {
return null
} I tried changing the return (
<div className={...>
{this.state.showBanner ? <BannerContent /> : null}
</div>
) This seems to have fixed the issue as well and doesn't require us to Good luck everyone! |
@gzhihao Yes, I made sure I was following all of the config rules and I tried both emotion and styled-components. Never ended up figuring it out because I thankfully had a working backup which I switched to for time saving's sake. |
I encounter similar issue lately again. The styling issue only happen in production build when I accessed the page directly from the url. If I navigate from other page, it's just fine. |
I had the same issue as well and eventually found I had the same problem as @gzhihao. I was using CSS classes that weren't imported on that particular page. |
I just ran into a similar problem as @gzhihao mentioned. In production, if I navigated to a specific page, it would only load CSS I had required in I'm testing moving my main styles.css I imported in Edit: This seemed to resolve the issue for me. |
I also had the same issue running Styled Components on Netlify. Installing gatsby-plugin-styled-components and adding it to my config file did the trick. Note: I had to clear my browser cache to see the changes. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m Thanks again for being part of the Gatsby community! |
For those that might be using Material UI and running into this problem, it was simply a matter of installing gatsby-plugin-material-ui for me! 😄 |
Description
CSS styles are loading when running 'gatsby develop' however, when deploying to Netlify or Surge, the styles do not load. Here are some of the solutions I tried:
gatsby-plugin-sass
to1.0.19
These solutions don't seem to correct the issue of the styles not loading. Also I tried deploying to surge.sh and I'm still getting no-styles deployment.
I'm pretty befuddled at this point even after looking at similar issues
Steps to reproduce
Netlify
https://github.com/DanStockham/tootles-bar
Surge
https://github.com/DanStockham/tootles-bar
gatsby build
surge public/
Expected result
Actual result
What happened.
![image](https://user-images.githubusercontent.com/11827054/39162438-7be823a4-4743-11e8-8bd7-d1395b7e46a0.png)
Environment
1.9.253
:1.1.50
:v8.9.4
File contents (if changed):
gatsby-config.js
:package.json
:gatsby-node.js
:gatsby-browser.js
:gatsby-ssr.js
:The text was updated successfully, but these errors were encountered: