# Preview problem - Internal Server Error 500

**URL:** <https://community.prismic.io/t/preview-problem-internal-server-error-500/5772>\
**Category:** Developing with Prismic\
**Tags:** nextjs\
**Created:** [June 14, 2021, 5:24pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772 "2021-06-14T17:24:56Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrzej](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@andrzej](https://community.prismic.io/u/andrzej)\
**Post date:** [June 14, 2021, 5:24pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/1 "2021-06-14T17:24:57Z")

</div>

Could I get some assistance as I'm driving myself crazy with this one.

When I click on the 'Preview' icon in Prismic I am taken to the server and I see various url params, but just get an "Internal Server Error" 500 response.

I've followed the docs, as well as the troubleshooting guide, but am still very much stuck. Hoping my use case might help others who end up in a similar corner (whatever corner that may be ;-) )

So, first off I've created the pages/api/preview js file and ensured that it is importing the correct environment values in Client for the req. I've also checked that the linkResolver looks in order. Seems simple enough.

I've checked the browser has got cookies set (I see x2 cookies).  
I've also set the preview site address in the Prismic settings UI to match up with my local dev environment ([http://localhost:3000](http://localhost:3000)) - I've tried my public address too - both exhibit the same error behaviour.

Which leaves me to think that the issue lies in my getStaticProps in my dynamic [uid].js page - does this look ok?

```auto
export async function getStaticProps({ params, preview = null, previewData = {} }) {
  
  const { ref } = previewData
  const family = await Client().getByUID("family", params.uid, ref ? { ref } : null) || {}
  const mySuperGraphQuery = `{
family {
name
creations
pronounced
title_holder {
...title_holderFields
lifeevents {
...lifeeventsFields
}
}
predecessors {
...predecessorsFields
}
family_members {
...family_membersFields
}
}
}`
  const fullFamily = await Client().getByUID('family', params.uid,
      { 'graphQuery': mySuperGraphQuery, lang: 'en-gb', pageSize : 1, page : 1 }
    );

  return {
    props: {
      preview,
      family,
      fullFamily
    }
  }
}

```

Any help, would be really appreciated!

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [June 15, 2021, 9:24am UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/3 "2021-06-15T09:24:42Z")

</div>

Hey Andrzej,

I'm guessing you had some cookies that didn't get cleared and are not out of date. If you clear these and start again it should work. The cookies you'll want to clear are:

- io.prismic.preview
- \_next\_preview\_data
- \_prerender\_bypass

Then to make sure this doesn't happen again in the future, make sure you add a exit preview button to clear the next.js cookie.

> **[Previews with Next.js](https://prismic.io/docs/technologies/previews-nextjs#1.3.-exit-next.js-preview-button)**
>
> This article will show you how to preview content changes without publishing your document or rebuilding your project.

---

<div class="post-metadata">

**Author:** ![andrzej](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@andrzej](https://community.prismic.io/u/andrzej)\
**Post date:** [June 15, 2021, 5:14pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/4 "2021-06-15T17:14:30Z")

</div>

Thanks Phil - I figured it out, and it was the silliest thing: I'd forgotten to set the environment vars in Vercel. Doh!

Might be a good checklist item for your documentation for those that are as forgetful as me...

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [June 16, 2021, 11:03am UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/5 "2021-06-16T11:03:33Z")

</div>

I'm glad you figured this out. That's a really good catch. I'll definitely update the docs.

Would you mind sharing your fix here for anyone who comes across this issue on the forum?

Thanks.

---

<div class="post-metadata">

**Author:** ![andrzej](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@andrzej](https://community.prismic.io/u/andrzej)\
**Post date:** [June 16, 2021, 3:58pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/6 "2021-06-16T15:58:33Z")

</div>

Thanks - in more detail:

When developing locally I was holding the prismic token etc within the .env file, which for security reasons is not synced to my git repo. When Vercel performs its build it gets the code from the repo so doesn't have the environment variables. Hence the Error 500.

The fix was to go to Vercel and go to Project -\> Settings -\> Environment Variables and set them there.

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [June 17, 2021, 2:37pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/7 "2021-06-17T14:37:53Z")

</div>

Thanks so much for sharing this 🙂 This will really help others.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [June 30, 2021, 2:05pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/8 "2021-06-30T14:05:04Z")

</div>

closed on June 30, 2021, 2:05pm UTC as resolved,  flag & select 'Something Else' to reopen.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [July 13, 2021, 3:46pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/9 "2021-07-13T15:46:35Z")

</div>

Opened on July 13, 2021, 3:46pm UTC



---

<div class="post-metadata">

**Author:** ![andreas.kratzel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/andreas.kratzel/32/415_2.png) [@andreas.kratzel](https://community.prismic.io/u/andreas.kratzel)\
**Post date:** [July 13, 2021, 3:48pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/10 "2021-07-13T15:48:59Z")

</div>

Hey, so I am facing a similar issue. I use next.js on my application and I am receiving 500 Internal Server Errors on my **unpublished** documents. It works fine for all other documents.

I saw that [Troubleshooting: Previews](https://community.prismic.io/t/troubleshooting-previews/5449#are-you-trying-to-preview-an-unpublished-document-9) provides help here, but adding the toolbar js on my 404 page did not help unfortunately. The rest is pretty much set up as it is recommended here [Previews with Next.js - Prismic](https://prismic.io/docs/technologies/previews-nextjs)

Is there a proper way to preview unpublished docs?

Thanks!

---

<div class="post-metadata">

**Author:** ![andrzej](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@andrzej](https://community.prismic.io/u/andrzej)\
**Post date:** [July 13, 2021, 4:27pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/11 "2021-07-13T16:27:44Z")

</div>

Hi Andreas - Are you using a token that provides access to "Master + Versions" - sounds like you might need that in place...?

---

<div class="post-metadata">

**Author:** ![andreas.kratzel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/andreas.kratzel/32/415_2.png) [@andreas.kratzel](https://community.prismic.io/u/andreas.kratzel)\
**Post date:** [July 16, 2021, 6:01am UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/12 "2021-07-16T06:01:34Z")

</div>

Do you mean "Master + Releases"?

Currently my token is master only.

---

<div class="post-metadata">

**Author:** ![andrzej](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@andrzej](https://community.prismic.io/u/andrzej)\
**Post date:** [July 16, 2021, 6:46am UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/13 "2021-07-16T06:46:03Z")

</div>

Yes, sorry, that's what I was thinking. I don't know for sure that this will solve the problem, but just a thought!

---

<div class="post-metadata">

**Author:** ![samlittlefair](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/samlittlefair/32/696_2.png) [@samlittlefair](https://community.prismic.io/u/samlittlefair)\
**Post date:** [July 16, 2021, 1:13pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/14 "2021-07-16T13:13:12Z")

</div>

@andreas.kratzel If @andrzej's suggestion doesn't work, you could send me a ZIP file or git repo containing your project, and I could try to find the source of the problem. Feel free to send it in a DM.

Best,  
Sam

---

<div class="post-metadata">

**Author:** ![samlittlefair](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/samlittlefair/32/696_2.png) [@samlittlefair](https://community.prismic.io/u/samlittlefair)\
**Post date:** [July 23, 2021, 11:43am UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/16 "2021-07-23T11:43:28Z")

</div>

closed on July 23, 2021, 11:43am UTC, flag & select 'Something Else' to reopen.

This thread has been closed due to inactivity. [Flag to reopen](https://community.prismic.io/t/re-open-a-thread/2175).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 3:35pm UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/17 "2021-12-09T15:35:46Z")

</div>

Opened on December 9, 2021, 3:35pm UTC



---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [January 11, 2022, 10:10am UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/18 "2022-01-11T10:10:18Z")

</div>

Split this topic on January 11, 2022, 10:10am UTC

A post was split to a new topic: [500 error on preview](https://community.prismic.io/t/500-error-on-preview/8603)

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [January 11, 2022, 10:10am UTC](https://community.prismic.io/t/preview-problem-internal-server-error-500/5772/19 "2022-01-11T10:10:26Z")

</div>

closed on January 11, 2022, 10:10am UTC, flag & select 'Something Else' to reopen.


