<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: strangeforloop</title>
    <description>The latest articles on DEV Community by strangeforloop (@strangeforloop).</description>
    <link>https://dev.to/strangeforloop</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F245100%2Fdb883888-644d-45ed-a078-60ce8fd2384b.jpeg</url>
      <title>DEV Community: strangeforloop</title>
      <link>https://dev.to/strangeforloop</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/strangeforloop"/>
    <language>en</language>
    <item>
      <title>Bringing in the 20s with Tips for Using Gatsby</title>
      <dc:creator>strangeforloop</dc:creator>
      <pubDate>Thu, 02 Jan 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/strangeforloop/bringing-in-the-20s-with-tips-for-using-gatsby-28gj</link>
      <guid>https://dev.to/strangeforloop/bringing-in-the-20s-with-tips-for-using-gatsby-28gj</guid>
      <description>&lt;p&gt;Recently, I created a personal website/blog using GatsbyJS and learned a lot of things along the way. If you're new to GatsbyJS, I hope that the lessons I learned will help you with your project. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclaimer&lt;/em&gt;: This is NOT a Gatsby tutorial, but a set of Gatsby-related tips I learned while using Gatsby.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;And with that, let's get started!&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/g9582DNuQppxC/giphy-downsized-large.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/g9582DNuQppxC/giphy-downsized-large.gif" alt="Leonardo DiCaprio raising a glass from The Great Gatsby"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Gatsby?
&lt;/h2&gt;

&lt;p&gt;Gatsby is a static site generator for React. This means that the HTML, CSS, and JavaScript get rendered during &lt;strong&gt;build time&lt;/strong&gt; rather than &lt;strong&gt;run time&lt;/strong&gt; and thus doesn't need a server. So, if you're considering making a website where the content will generally be static, such as a personal website or a blog, Gatsby is a great option. Another possible reason to learn Gatsby would be either to build on your React skills :).&lt;br&gt;&lt;br&gt;
  As an aside, if you don't have a personal website, I would encourage it. A personal website can act as a place to showcase who you are in the ways &lt;strong&gt;you&lt;/strong&gt; define. It's also a place to experiment with new things and be as creative as you want. A virtual playground, if you will.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisite Knowledge:
&lt;/h2&gt;

&lt;p&gt;A basic understanding of React. You don't have to be an expert, so don't let that scare you. However, it would be useful to have an understanding of functional components and JSX.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;An idea of how &lt;a href="https://graphql.org/"&gt;GraphQL&lt;/a&gt; works (I'll get to why below).&lt;br&gt;&lt;/p&gt;

&lt;p&gt;A basic understanding of Gatsby, of course. &lt;a href="https://www.gatsbyjs.org/tutorial/"&gt;Here&lt;/a&gt; is a beginner-friendly index page for learning all things Gatsby.&lt;/p&gt;
&lt;h2&gt;
  
  
  On to the Tips!
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Make Use of Starter Files
&lt;/h3&gt;

&lt;p&gt;As of posting, there 300+ &lt;a href="https://www.gatsbyjs.org/starters/?v=2"&gt;Gatsby starter files&lt;/a&gt; available to help you get started making the type of project you want.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---EOb7f62--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/whjf9uda1luhdtdlji8x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---EOb7f62--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/whjf9uda1luhdtdlji8x.png" alt="Examples of Gatsby Starter Files"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Advice for Issues with Gatsby CLI Being Removed
&lt;/h3&gt;

&lt;p&gt;It seems to be a fairly common issue to run into this error after installing various dependencies for your project:&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;ERROR                              &lt;br&gt;
There was a problem loading the local develop command. Gatsby may not be installed. Perhaps you need to run "npm install"?&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In my case, running  &lt;code&gt;npm install --save gatsby-plugin-typography react-typography typography&lt;/code&gt; &lt;br&gt;
removed the Gatsby CLI. Looking at similar issues on Github, it seems that sometimes, installing plugins with npm can end up uninstalling Gatsby. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZecmWw8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0flltgdlyv7xhjpbcvyp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZecmWw8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0flltgdlyv7xhjpbcvyp.png" alt="gatsby develop issue on github"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To fix this issue, I used yarn for dependency installs. I removed &lt;code&gt;package.json&lt;/code&gt; and the &lt;code&gt;/node_modules&lt;/code&gt; folder. Then I ran &lt;code&gt;yarn install&lt;/code&gt; and added the packages I needed with Yarn instead of npm.&lt;/p&gt;

&lt;p&gt;This solved my issue. For this reason, I'm currently using &lt;a href="https://yarnpkg.com/"&gt;Yarn&lt;/a&gt; as my package manager of choice when working with Gatsby.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--izz0uyzU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/q623w3p9y4f2dywb0i1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--izz0uyzU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/q623w3p9y4f2dywb0i1s.png" alt="Yarn package manager home page"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Utilize the Gatsby Pair Programming Option
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.gatsbyjs.org/contributing/pair-programming/"&gt;Gatsby Pair Programming&lt;/a&gt; is an truly &lt;em&gt;awesome&lt;/em&gt; resource and I can abcolutely recommend if you end up needing help. &lt;br&gt;&lt;br&gt;&lt;br&gt;
My advice is to come with very specific questions. I used this once in order to help me solve an issue routing to my individual blog posts and was able to ask in depth questions about why things are how they are as well as asking for advice on implementation. It felt like a very non-judgmental and helpful space. Time slots do fill up fairly quickly though!&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Learn to Effectively Utilize GraphQL's Capabilities
&lt;/h3&gt;

&lt;p&gt;GraphQL is query language that gives you access to your site's data. This means you can query the specific data you want to add to your pages. Gatsby provides access to GraphiQL, a GraphQL IDE available at  &lt;a href="http://localhost:8000/___graphql"&gt;http://localhost:8000/___graphql&lt;/a&gt; when you have the development server running. It is an excellent tool that allows you to visualize if the data coming back from your queries is what you expect it to be. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pfe2MI16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fl2uyx304dbqap07kd1h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pfe2MI16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fl2uyx304dbqap07kd1h.png" alt="screenshot of graphiql IDE"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;This can come in handy when trying to debug various types of problems.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When unexpected behavior occurs, you can easily create queries that show what data is being returned or if anything is being returned at all. I actually learned a lot about how to use this for debugging during the pairing session.&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Advice Based on Errors I Faced and How I Solved Them:
&lt;/h3&gt;
&lt;h4&gt;
  
  
  TypeError: Cannot read property 'page' of undefined &lt;br&gt;
&lt;/h4&gt;

&lt;p&gt;This is a common error that can occur with React projects. It is usually caused by one of the following:&lt;br&gt;&lt;/p&gt;

&lt;p&gt;It can mean that you're not importing or exporting the component properly,you're not referencing the component name correctly, or &lt;br&gt;
your component is not returning anything to render to the page.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  ENOENT: no such file or directory
&lt;/h4&gt;

&lt;p&gt;This can occur with changes to the &lt;code&gt;/public&lt;/code&gt; folder, such as when you delete or rename a file in the &lt;code&gt;/pages&lt;/code&gt; directory.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Why?&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Gatsby keeps track of these files in the &lt;code&gt;.cache&lt;/code&gt; folder for the purpose of loading your site faster. So make sure you clear the cache to make sure that everything's up to date and Gatsby isn't trying to load something from cache that doesn't actually exist.&lt;br&gt;&lt;br&gt; You can accomplish this by either deleting the &lt;code&gt;.cache folder&lt;/code&gt;, running &lt;code&gt;gatsby clean&lt;/code&gt;, or adding &lt;code&gt;gatsby clean&lt;/code&gt; as a script in the &lt;code&gt;package.json&lt;/code&gt; file like shown below.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scripts": {
  // other scripts here
  "clean": "gatsby clean",
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Unknown field 'X' on type 'Y'
&lt;/h4&gt;

&lt;p&gt;This could mean you are trying to query for something that doesn't exist. My advice is to open the GraphiQL's interactive display to see what data you do have available. &lt;/p&gt;

&lt;h3&gt;
  
  
  6. Use 'gatsby build' for Deployment
&lt;/h3&gt;

&lt;p&gt;When deploying  to any hosting site (in my case, I used Netlify), make sure you run &lt;code&gt;gatsby build&lt;/code&gt; instead of &lt;code&gt;gatsby develop&lt;/code&gt;. Other wise, the hosting site won't build your project properly. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;The two commands seem very similar-- because they are, but main difference is that &lt;code&gt;gatsby build&lt;/code&gt; runs additional instructions such as creating the static HTML pages needed to be rendered by a browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  BONUS: Other Helpful Resources:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.gatsbyjs.org/docs/styling/"&gt;The Many Styling Options for React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.awwwards.com/websites/portfolio/"&gt;Fancy Portfolio Inspiration to Drool Over&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>react</category>
      <category>blog</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
