Gatsby build fails due to access token issue
20 replies
Last updated: Apr 1, 2021
F
Our Gatsby build stopped working on Saturday:
It seems that it’s not getting any data from Sanity, which is weird as it works locally running
Even worse is that it now seems to randomly sometimes work when we run a
Me and
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; | ^
gatsby serve.We did change our production datasett from
publicto
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 buildlocally.
Me and
user Q
is working on the project.Mar 29, 2021, 11:16 AM
B
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
B
Also, could you try running
gatsby cleanfirst?
Mar 29, 2021, 11:55 AM
B
If you run with
DEBUG=sanity gatsby buildyou should get some additional debug info about what the sanity client is actually doing
Mar 29, 2021, 11:55 AM
F
Will try
Mar 29, 2021, 11:56 AM
F
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
F
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
F
Wait, I was jumping between some branches and forgot to update my
.env.*files
Mar 29, 2021, 12:02 PM
B
Was about to say it looks very much like an issue with access tokens 🙂
Mar 29, 2021, 12:02 PM
F
I’ll add
DEBUG=sanityto the build server and see what goes on there
Mar 29, 2021, 12:03 PM
B
const { address, phone } = data.allSanitySiteSettings.edges[0].node;
Mar 29, 2021, 12:04 PM
F
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
F
Does
Deploy Studioaccess token not give you read access to data? (If I reuse the same token for sanity and gatsby)
Mar 29, 2021, 1:31 PM
B
No, you'll need a token with read access
Mar 29, 2021, 1:31 PM
F
Does
Writeaccess also allow me to deploy the studio?
Mar 29, 2021, 1:32 PM
B
I think so, but I'd recommend using separate tokens in any case
Mar 29, 2021, 1:32 PM
F
So I need two different tokens then on my build server? One for gatsby with
Readand one for deploying sanity with
Deploy Studio?
Mar 29, 2021, 1:33 PM
B
If you are using
sanity deployto deploy your studio, yes (https://www.sanity.io/docs/deployment#59a23cd85193 ).
Mar 29, 2021, 1:34 PM
F
It would be nice in the future if I could create one key for my build server that have access to multiple things (Both
readand
Deploy Studio).
Mar 29, 2021, 2:49 PM
B
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
F
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.