Hi, Nextjs newbie here. I have a new Nextjs app connected with Prismic (npx create-next-app@latest ). At first I could build the app (npm run build ), but after adding Prismic Slicemachine with npx @slicemachine/init@latest I get two errors regarding the build-in API preview of Prismic (see screenshots). Can anybody help me please? Thank you!
Error occurred prerendering page "/api/preview". Read more: Prerender Error | Next.js Error: Page with dynamic = "error" couldn't be rendered statically because it used request.url .
Error occurred prerendering page "/api/exit-preview". Read more: Prerender Error | Next.js Error: Page with dynamic = "error" couldn't be rendered statically because it used draftMode().disable() .
So, I couldn't even get that far, which is not normal. I wasn't even able to create a repository:
after running
bunx @slicemachine/init@latest
or
npx @slicemachine/init@latest
Either one of these wouldn't let me create a repo. I was able to hook up to an existing one though.
Creating new repository dannyforumtest ...
→ Failed to create repository `dannyforumtest`
Error: Failed to create repository `dannyforumtest`
at PrismicRepositoryManager.create (/home/username/.npm/_npx/b6923b01b288b666/node_modules/@slicemachine/manager/dist/managers/prismicRepository/PrismicRepositoryManager.cjs:125:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Task.task (/home/username/.npm/_npx/b6923b01b288b666/node_modules/@slicemachine/init/dist/SliceMachineInitProcess.cjs:625:11)
I have not been able to get past programmatically creating a new repository. I'm kind of surprised that this isn't catching more eyeballs. Could it really be just us? Although, 1.18.0 is out, maybe that fixed it?
I can see this in your project now, and I can't figure out why because I'm not getting it in other Next.js projects. So, I'm reaching out to my team to get some help.
output: 'export' configures Next.js to build a 100% static version of your website. In this mode, Prismic previews are not supported.
The /api/preview and /api/exit-preview endpoints fail because they are not static route handlers. You can find more information about output: 'export''s limitations here: Deploying: Static Exports | Next.js
Prismic previews requires a server that can serve dynamic requests (i.e. not static). A page's content must change during a preview, which cannot be accomplished with output: 'export'.
I recommend removing output: 'export' unless you need a 100% static website. If you need output: "export" and don't need to support previews, remove the following:
src/app/api/preview/route.ts
src/app/api/exit-preview/route.ts
src/app/api/revalidate/route.ts
<PrismicPreview> in app/layout.tsx
enableAutoPreviews() in src/prismicio.ts
Note that even with a dynamic website (without output: 'export'), your pages will still be statically rendered if you do not use any dynamic functions or uncached fetch() requests. Prismic's recommended setup, which is included in our starters, is static by default.