Trouble publishing data on deployed Sanity studio, solved by adding production environment variables

25 replies
Last updated: Apr 15, 2021
HALP! I am having trouble publishing data on my deployed studio with Sanity. When I run the studio locally, I can change data and click publish and I see the toast immediately that it was published. My deployed studio doesn't show the toast and the publish button just stays green in limbo. I can refresh the studio and see that my changes are present in the editor, so it seems the draft is being saved but not published, because I can then reload my local development copy and it was publish right away with that drafted change.
Does anyone know why my deployed studio won't complete the publish process?
Apr 15, 2021, 2:26 PM
Additionally, each time that I deploy my studio, running
sanity deploy
, I am left with a series of modified files after the process completes. Is this normal?
Apr 15, 2021, 2:27 PM
I am left with a series of modified files after the process completes.
That’s normal. It’s the result of building the studio .
For the issue in your deployed studio, I assume there are no unusual errors in the console?
Apr 15, 2021, 2:37 PM
Oh goodness. There is an error in the console.
Apr 15, 2021, 2:37 PM
It's odd that the error is not present in my local, though.
Apr 15, 2021, 2:38 PM
Uncaught (in promise) Error: Configuration must contain `projectId`
    at t.initConfig (app.bundle.js?50e00c9defadd899b772:1213)
Apr 15, 2021, 2:39 PM
Have you tried deploying more than once?
I came across
this post from last year, but unfortunately the problem seemed to resolve itself for the person (though that’s assuming the issues in your deployed studio are tied to this error).
Apr 15, 2021, 2:43 PM
Have you tried deploying more than once?
I came across
this post from last year, but unfortunately the problem seemed to resolve itself for the person (though that’s assuming the issues in your deployed studio are tied to this error).
Apr 15, 2021, 2:43 PM
Yes I deployed once again this morning.
Apr 15, 2021, 2:43 PM
I will try again.
Apr 15, 2021, 2:43 PM
Are you configuring for multiple environments in your env files, and if so, does anything differ besides the dataset?
Apr 15, 2021, 2:44 PM
I have not changed anything about the environment from the start, but I will look at my commits and see if something changed inadvertently.
Apr 15, 2021, 2:45 PM
user A
no dice. The dataset is the same on both local and on sanity.studio : "production".
Apr 15, 2021, 2:48 PM
K, checking into it.
Apr 15, 2021, 2:52 PM
I assume you’re using your set slug on publish snippet? If so, has your deployed studio worked in the past with it?
Apr 15, 2021, 2:55 PM
Good question. I'm not sure that my snippet would cause an issue with the projectId, but it does work locally and has also worked deployed in the past.
Apr 15, 2021, 2:58 PM
That seemed like the most obvious place for me to look (since that code prevents publishing), but it does work locally.
Apr 15, 2021, 2:59 PM
I can both publish new Tags and I can publish edited Tags.
Apr 15, 2021, 3:01 PM
I find it especially karmic that a developer is having their own "it works on my machine" moment here. 😆
Apr 15, 2021, 3:02 PM
I find it especially karmic that a developer is having their own "it works on my machine" moment here. 😆
Apr 15, 2021, 3:02 PM
user A
I'm going through the code of my slug documentAction. It uses the environment variables to instantiate a sanity client. Is there an issue with using these variables in production? I am certain that I've used this code in production before, but I've had egg on my face as early as two days ago so I'm willing to be wrong again.
Apr 15, 2021, 3:16 PM
Circling back here,
user A
, to say that the eggs are back and this time they are scrambled.
I disabled my slug snippet and publishing is working again in the deployed version of the studio. I will have to spend some time discovering the errors of my ways here. My thoughts are that this has to do with a difference in the availability of the environment variables that I have access to on the deployed studio, so I will go back to reading the documentation around that. Once I figure it out I'll be sure to bring those changes back to my community snippet as well!

Thanks for the rubber ducky'ing.
🙏
Apr 15, 2021, 4:39 PM
Okay, thanks Ken. I’d be interested to hear how you solve it.
Apr 15, 2021, 4:41 PM
user A
I had a
.env.development
but not a
.env.production
. I found this line in the documentation:

For instance, a development configuration would be named .env.development while a production version would be .env.production
https://www.sanity.io/docs/studio-environment-variables
I might include a note on my snippet documentation about the need for production environment variables to expose the connection information that enables this snippet to pull from the database and check for other existing slugs before approving a publish.

I simply copied my a
.env.development
and named it
.env.production
and now it works!
Apr 15, 2021, 4:49 PM
user A
I had a
.env.development
but not a
.env.production
. I found this line in the documentation:

For instance, a development configuration would be named .env.development while a production version would be .env.production
https://www.sanity.io/docs/studio-environment-variables
I might include a note on my snippet documentation about the need for production environment variables to expose the connection information that enables this snippet to pull from the database and check for other existing slugs before approving a publish.
Apr 15, 2021, 4:49 PM
Final note: I'm starting to realize that y'all have made things too easy. While I have read over this part of the documentation and I did so again, specifically, when I started working on this snippet; it turns out that I only read the first sentence and then moved on because my problem was easily resolved.
This time, reading the second sentence resolved my problem...


😂
Thanks!
Apr 15, 2021, 4:52 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?