NextJS Preview mode only works locally


I’m currently building a preview mode for our editors. The preview has been setup in accordance with the NextJS Preview mode docs and DatoCMS docs. Everything works completely fine locally, however, when a deploy to Netlify is made It creates a client side exception error (500) - once cookies are set.

Deploy preview:
Setting preview cookies:

@netlify/plugin-nextjs - v4.2.1 - any higher upgrade to this plugin also causes the entire site to client side exception error

Seems similar to this issue: NextJS preview works locally but not on Netlify

Any help would greatly be appreciated!

Hi @Y-Ollie,

The previous issue is very old and the version of the plugin being used then is now unsupported. So we can keep that aside for now.

Do you have any deploys in which you used the latest version of the plugin? We can escalate this to the engineers, but if they see an older version of the plugin, they’d first flag that.

Hi @hrishikesh!

Thanks for reaching out.

Here is a preview deploy with the most recent version of the plugin:


Just a quick update, we’ve updated the bug here: [Bug]: Error during deploy: "Error: ENOENT: no such file or directory, copyfile" · Issue #1366 · netlify/next-runtime · GitHub

Thanks for the update!

Hi Hillary, Has there been any update on this? We are currently unable to move forward on a lot of our projects.

Sorry for the delay in response! Our developers just gave you some feedback in the GitHub issue yesterday, and will likely respond there going forward.

Please give that advice a try and let us know how it goes!

Hey! We tried different versions of the plugin but still no luck :confused:

Any further advice from the developers?


No, because we haven’t yet seen the results of your experiments.

Please link us to deploy logs where you try the latest version of the plugin, and we’ll be happy to look further. Suggest linking them here rather than just in the github issue since our Support team is not “Tracking” the github issue but we are tracking this thread :slight_smile:

1 Like

Hey Fool, thanks for getting back to us.

please see default deploys for both plugin version 4.9.3 & 4.11.1

4.9.3: Netlify App
4.11.1: Netlify App

– Update

I have found if we skip function cache we can get the site to build, however, I still seem to 500 if I set any cookie preview logic from the nextjs guides: Advanced Features: Preview Mode | Next.js

Implementing the basic logic to set preview cookies on /api/preview

export default function handler(req, res) {
  res.end('Preview mode enabled')

If you return to any page after the cookies are set the 500 error returns until the cookies are cleared.
Deploy w/ cookies on 4.11.1: Netlify App

Hi @Y-Ollie,

As mentioned in the helpdesk, we’ve escalated this to the developers.