ERROR #11321 PLUGIN while building in Gatsby

Viewed 2660

I'm trying to learn and write my first GatsbyJs porfolio, but Im getting an error while building this starter: https://www.gatsbyjs.org/starters/smakosh/gatsby-portfolio-dev/

Still didn't touch a single line of code... Tried deleting node_modules and npm install again but same error.


"gatsby-source-graphql" threw an error while running the sourceNodes lifecycle:

Response not successful: Received status code 401



  ServerError: Response not successful: Received status code 401
  
  - index.js:23 Object.exports.throwServerError
    [gatsby-portfolio-dev]/[apollo-link-http-common]/lib/index.js:23:17
  
  - index.js:48 
    [gatsby-portfolio-dev]/[apollo-link-http-common]/lib/index.js:48:21
  
  - task_queues.js:97 processTicksAndRejections
    internal/process/task_queues.js:97:5
  

not finished source and transform nodes - 1.135s
2 Answers

Since you have some environment variables in your gatsby-config.js (line 25), your project is not able to run.

{
      resolve: 'gatsby-source-graphql',
      options: {
        typeName: 'GitHub',
        fieldName: 'github',
        url: 'https://api.github.com/graphql',
        headers: {
          Authorization: `bearer ${process.env.GATSBY_PORTFOLIO_GITHUB_TOKEN}`, // here
        },
        fetchOptions: {},
      },
    },

Basically, you are not allowed to connect to GitHub to gather information and their API throws a 401 error (unauthorized).

Environment variables contain ids, tokens and other critical (and private) data that allows you to connect to some external APIs (GitHub in this case) and they must not be uploaded in the public repositories (for obvious reasons) and that's why the starter doesn't provide this information. You should add it to your project on your own. Take a look at GitHub's documentation to get your own API token.

If you check the CodeSandbox of the starter you are trying to run, they have an empty .env.development file where all those variables should be.

For further information, a look at Gatsby's documentation about Environment Variables.

Related