Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any import from next-sanity prevents Next.js static builds (output: 'export') #1899

Open
dylansmith opened this issue Nov 8, 2024 · 0 comments

Comments

@dylansmith
Copy link

dylansmith commented Nov 8, 2024

Describe the bug

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';
import groq from '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.

import { defineQuery } from 'next-sanity';
import { groq } from 'next-sanity';

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?

@sanity/cli (global)                   3.59.0 (latest: 3.63.0)
@sanity/document-internationalization   3.1.0 (up to date)
@sanity/image-url                       1.0.2 (latest: 1.1.0)
@sanity/vision                         3.59.0 (latest: 3.63.0)
sanity                                 3.59.0 (latest: 3.63.0)

What operating system are you using?

MacOS 13.4 (22F66)

Which versions of Node.js / npm are you running?

10.8.2
v22.6.0

Additional context

Add any other context about the problem here.

Security issue?

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant