You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We recently tried to build our Next.js (14.2.14) project using static exports via the output: 'export' config. However, the build kept failing with the error message:
> Server Actions are not supported with static export.
As the message says, you cannot render an app with Server Actions as a static site, but we were not using any server actions in our code. After hours of trying to figure out why Next was behaving this way, I isolated the issue to imports from next-sanity like these:
import{defineQuery}from'next-sanity';
It appears as though the module packages/next-sanity/src/visual-editing/server-actions/index.ts is the culprit here. Possibly there is a chain of imports in place that whenever you import from next-sanity this module is resolved as well. In our case (as will be for many others using Sanity) our Next.js pages will run a query against Sanity on every page request so if the import from next-sanity is in this codepath then all pages will not be able to be statically generated.
I was able to workaround this issue by changing the following imports:
// import { defineQuery } from 'next-sanity';import{defineQuery}from'groq';// import { groq } from 'next-sanity';importgroqfrom'groq'`;// import { createClient } from 'next-sanity';import{createClient,SanityClient}from'@sanity/client';
To Reproduce
Steps to reproduce the behavior:
Add an import from next-sanity to any Next.js page or a module that is imported into a page, e.g.
Describe the bug
We recently tried to build our Next.js (
14.2.14
) project using static exports via theoutput: 'export'
config. However, the build kept failing with the error message:As the message says, you cannot render an app with Server Actions as a static site, but we were not using any server actions in our code. After hours of trying to figure out why Next was behaving this way, I isolated the issue to imports from
next-sanity
like these:It appears as though the module packages/next-sanity/src/visual-editing/server-actions/index.ts is the culprit here. Possibly there is a chain of imports in place that whenever you import from
next-sanity
this module is resolved as well. In our case (as will be for many others using Sanity) our Next.js pages will run a query against Sanity on every page request so if the import fromnext-sanity
is in this codepath then all pages will not be able to be statically generated.I was able to workaround this issue by changing the following imports:
To Reproduce
Steps to reproduce the behavior:
Add an import from
next-sanity
to any Next.js page or a module that is imported into a page, e.g.Expected behavior
Imports from
next-sanity
that are unrelated to visual editing should not break static builds in Next.js.Which versions of Sanity are you using?
What operating system are you using?
MacOS 13.4 (22F66)
Which versions of Node.js / npm are you running?
Additional context
Add any other context about the problem here.
Security issue?
N/A
The text was updated successfully, but these errors were encountered: