Gatsby build fails due to access token issue

20 replies
Last updated: Apr 1, 2021
Our Gatsby build stopped working on Saturday:

success Rewriting compilation hashes - 0.001s
success Building HTML renderer - 38.462s
failed Building static HTML for pages - 0.304s
error Building static HTML failed for path "/404/"

  41 |     `
  42 |   );
> 43 |   const { address, phone } = data.allSanitySiteSettings.edges[0].node;
     |                                                                  ^
It seems that it’s not getting any data from Sanity, which is weird as it works locally running
gatsby serve
.We did change our production datasett from
public
to
private
, but all keys seems to be setup correctly so I’m not sure thats the problem.Is it somehow related to the new apiVersioning? Or something else?

Even worse is that it now seems to randomly sometimes work when we run a
gatsby build
locally.
Me and
user Q
is working on the project.
Mar 29, 2021, 11:16 AM
The new api version is opt-in, so shouldn't affect existing builds/sites. Do you have some more details about the error you get? Looks like there might be a stack trace hidden in the output somewhere.
Mar 29, 2021, 11:51 AM
Also, could you try running
gatsby clean
first?
Mar 29, 2021, 11:55 AM
If you run with
DEBUG=sanity gatsby build
you should get some additional debug info about what the sanity client is actually doing
Mar 29, 2021, 11:55 AM
Will try
Mar 29, 2021, 11:56 AM
This line seems important:

warn The gatsby-source-sanity plugin has generated no Gatsby nodes. Do you need it?
Mar 29, 2021, 11:59 AM
This as well:
warn [sanity] `overlayDrafts` is set to `true`, but no token is given
info [sanity] Fetching remote GraphQL schema
info [sanity] Transforming to Gatsby-compatible GraphQL SDL
info [sanity] Stitching GraphQL schemas from SDL
success onPreBootstrap - 0.261s
success createSchemaCustomization - 0.010s
info [sanity] Fetching export stream for dataset
info [sanity] Done! Exported 0 documents.
Mar 29, 2021, 12:00 PM
Wait, I was jumping between some branches and forgot to update my
.env.*
files
Mar 29, 2021, 12:02 PM
Was about to say it looks very much like an issue with access tokens 🙂
Mar 29, 2021, 12:02 PM
I’ll add
DEBUG=sanity
to the build server and see what goes on there
Mar 29, 2021, 12:03 PM
const { address, phone } = data.allSanitySiteSettings.edges[0].node;
The error you get at this line ^ is likely caused by the same underlying issue since the frontend here assumes the settings document can actually be fetched (but if the token doesn't grant read access to the private dataset this will be undefined)
Mar 29, 2021, 12:04 PM
I get a similare issue on the build server,
info [sanity] Done! Exported 0 documents.
<https://github.com/Alv-no/alv-website/pull/295/checks?check_run_id=2218237135#step:5:18|18>
. So I guess it doesn’t pick up the access token correctly. But Thanks! Now at least I know what to debug.
Mar 29, 2021, 12:11 PM
Does
Deploy Studio
access token not give you read access to data? (If I reuse the same token for sanity and gatsby)
Mar 29, 2021, 1:31 PM
No, you'll need a token with read access
Mar 29, 2021, 1:31 PM
Does
Write
access also allow me to deploy the studio?
Mar 29, 2021, 1:32 PM
I think so, but I'd recommend using separate tokens in any case
Mar 29, 2021, 1:32 PM
So I need two different tokens then on my build server? One for gatsby with
Read
and one for deploying sanity with
Deploy Studio
?
Mar 29, 2021, 1:33 PM
If you are using
sanity deploy
to deploy your studio, yes (https://www.sanity.io/docs/deployment#59a23cd85193 ).
Mar 29, 2021, 1:34 PM
It would be nice in the future if I could create one key for my build server that have access to multiple things (Both
read
and
Deploy Studio
).
Mar 29, 2021, 2:49 PM
I'd recommend having separate tokens for separate things, so that if one accidentally gets leaked it's easier to reason about the impact.
Mar 30, 2021, 2:25 PM
If something gets leaked from my build server then most likely all tokens from the build server gets leaked. As such it doesn’t make sense to have one token for gatsby read access and one for sanity deploy studio access as the build server needs both. It would be easier to reason about impact if I know that I can delete and replace a singel token for my build server.
Apr 1, 2021, 12:32 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?