Next.js 13.5 type error with preview routes

Next.js 13.5.1 causes the following type error related to api/preview/route.ts and api/exit-preview/route.ts.

Type error: Route "app/api/preview/route.ts" has an invalid export:
  "Promise<void>" is not a valid GET return type:
    Expected "Response | Promise<Response>", got "Promise<void>".
      Expected "Promise<Response>", got "Promise<void>".
        Expected "Response", got "void".

We get exactly the same error. All was working without any problem before. We use 13.5.2.

Hey Team,

I'll be happy to help.

Can you show me how your route resolver looks?

Also if one of you would be kind enough to share one of your project with me so I can test on my end.

Thanks.

this is the linkResolver function

export const linkResolver = (doc: FilledLinkToDocumentField) => {
  if (doc.isBroken) {
    return "/404";
  }

  if (doc.type === PRISMIC_TYPES.PAGE && doc.uid !== HOMEPAGE_UID) {
    return `/${doc.uid}`;
  }

  return "/";
};

Hey @Phil, thanks for taking a look!

Am I able to PM you through this forum? If so, I can share some other details.

Here's our current routes:

const routes: prismic.ClientConfig["routes"] = [
  {
    type: "homepage",
    path: "/",
  },
  {
    type: "page",
    path: "/:uid",
  },
  {
    type: "industry",
    path: "/industry/:uid",
  },
  {
    type: "news",
    path: "/news",
  },
  {
    type: "news_post",
    path: "/news/:uid",
  },
  {
    type: "media",
    path: "/media",
  },
  {
    type: "media_post",
    path: "/media/:uid",
  },
  {
    type: "careers",
    path: "/careers",
  },
];

I've sent you a pm @nathan. You can send me your project there.

Thanks.

@Phil We have exactly the same problem. We can't deploy to production anymore.

I also have the same issue. I'm using nextjs and deploying on vercel.
As a temporary workaround, I deployed the site without the preview folders.
Hope we can resolve this soon.

So is everyone only experiencing this in production or do you get this error locally as well?

@Phil Just in production

Thanks. I'm looking in to it

I can reproduce when running npm run build locally. Thanks!

1 Like

Me too, yarn build reproduce the bug in local @Phil @fakhreddine
I just check again. Sorry

Is there any news about this problem ?
Please @jamesminxyz Can you explain us how you can deployed the site without the preview folders ?

Hi @ali. As a temporary workaround, I added underscores to the route.js files. Obviously you can't use preview on production this way, but it works with Vercel.
image

When I am in local dev mode, I just remove the underscores to use the preview function locally.

Hi @here,

The error should be fixed as of @prismicio/next v1.3.5.

This wasn't an error in our package, but instead a breaking type change in Next.js.

Developers will need to make a change to the /api/preview endpoint, as described in this PR under "How to fix your project":

We've opened a PR that updates @slicemachine/init to generate the updated endpoint code:

Thanks.

1 Like

Fix confirmed. Thanks so much @Phil and @angeloashmore!

1 Like

Next v13.5.3, released today, and reverted the type regression

Our changes are still good, but they are no longer required if you update to at least Next.js v13.5.3.