datocms / gatsby-source-datocms

Official GatsbyJS source plugin to pull content from DatoCMS
MIT License
140 stars 50 forks source link

401 INVALID_SITE #85

Closed dingyi closed 4 years ago

dingyi commented 4 years ago

When I run gatsby develop, it said:

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

401 INVALID_SITE (details: {})

but I still can query data from DatoCMS in http://localhost:8000/___graphql

How can I fix this error warning?

matjack1 commented 4 years ago

@dingyi this is very strange! You say that in the GraphiQL you can see data, but can you query data also in your code? Is that only a wrong warning or are you having some issues?

LluisArevalo commented 4 years ago

I was getting the same problem when running gatsby build. In my case, the problem was with the environment variables values:

gatsby-config.js

require('dotenv').config({
  path: `.env.${process.env.NODE_ENV}`
});

module.exports = {
  plugins: [{
    resolve: `gatsby-source-datocms`,
      options: {
        apiToken: process.env.DATOCMS_READONLY_TOKEN,
        // Preview the latest version of records instead of the published one
        previewMode: false,
        // Disable automatic reloading of content when some change occurs on DatoCMS:
        disableLiveReload: false,
        apiUrl: 'https://site-api.datocms.com'
      }
  }]
}

I'm using the NODE_ENV value to load the correct variables, and during the build NODE_ENV is production. Once I created the correct files, everything went well.

matjack1 commented 4 years ago

normally @dingyi @LluisArevalo this happens when you haven't specified the DATO_API_TOKEN either in your .env file or directly in the gatsby-config.js file. Can you please give me more details on how to reproduce the problem?

If you want to share your repo with me, either here if it's public or over support@datocms.com if it's private.

matjack1 commented 4 years ago

thank you for the update @LluisArevalo !

dingyi commented 4 years ago

@matjack1 Thank you! I tried DATO_API_TOKEN and it works now!

matjack1 commented 4 years ago

Excellent, thank you @dingyi for your feedback, I'm closing this for now then :)