Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Hi, Can someone tell me the proper way to enter the projectID using ENV’s in the sanity.json. If I hard code, works great, anything else and and it’s not finding the projectId....

8 replies
Last updated: Jan 24, 2021
Hi, Can someone tell me the proper way to enter the projectID using ENV’s in the sanity.json. If I hard code, works great, anything else and and it’s not finding the projectId. ENV’s are in .env.local
"api": {
    "projectId": "PLACEHOLDER_ENV_VARIABLES_WILL_HANDLE_FOR_US",
    "dataset": "PLACEHOLDER_ENV_VARIABLES_WILL_HANDLE_FOR_US"
  }
Jan 6, 2021, 5:17 PM
They need to be in studio folder and be named
.env.development
and
.env.production
I think
Jan 6, 2021, 5:22 PM
and should not be referenced in sanity.json file like that. you can delete the api section
Jan 6, 2021, 5:23 PM
ok thanks, I’ll give that a go
Jan 6, 2021, 5:28 PM
https://www.sanity.io/docs/studio-environment-variables#dot-env-files-env-f5e9e3158896 here you can read a bit more about how they should me named etc
Jan 6, 2021, 5:31 PM
Makes sense, production is working, it’s just localhost that is not finding the project ID. I put in the studio folder
Jan 6, 2021, 5:33 PM
Nice, that’s all it was. Cheers
user T
Jan 6, 2021, 5:36 PM
Hey guys, I am facing the same problem, and I followed the instructions of
user T
(removed the api section from sanity.json), and I placed a .env.development in the root folders with the variables SANITY_STUDIO_API_PROJECT_ID and SANITY_STUDIO_API_DATASET defined.However, when I run sanity start, sanity says "Project configuration required before starting studio" and forces me to select a project or create a new one ...

Any ideas how I could fix that?
Jan 23, 2021, 10:45 AM
(found the answer thanks to
user Q
, commented here: https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1611482229244200 )
Jan 24, 2021, 12:37 PM

Sanity– build remarkable experiences at scale

Sanity is a modern 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?