-
Notifications
You must be signed in to change notification settings - Fork 445
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
Can't embed next-studio in Next.js (v15) app - Webpack TypeError - createContext is not a function #8291
Comments
The solution I had for running webpack and the app router is to wrap the studio in a 'use client' component e.g. page.tsx import { Wrapper } from "./studio-wrapper";
export const dynamic = "force-static";
export { metadata, viewport } from "next-sanity/studio";
export default function StudioPage() {
return <Wrapper />;
} Wrapper.tsx "use client";
import config from "./../../../../sanity.config";
import { NextStudio } from "next-sanity/studio";
export function Wrapper() {
return <NextStudio config={config} />;
} |
Thanks for your comment! Respectfully, that is not documented in next-sanity install instructions, and could potentially bleed secrets through the client app depending on the auth pattern used.
I definitely want to keep the studio on the node server, and nothing indicates that this isn't possible?
Surely it's a bug / regression?
|
Documentation suggests you can 'use client' https://github.com/sanity-io/next-sanity?tab=readme-ov-file#embedded-sanity-studio // ./src/app/studio/[[...tool]]/page.tsx
Regarding secrets, take a look at their recommendations https://www.sanity.io/docs/environment-variables#c22c023216f9 |
Good pickup! Interesting however that the only time in the linked doco that 'use client' declaration is used is in your linked snippet, which is titled "Lower-level control with StudioProvider and StudioLayout". The 2 example code snippets above it (same doco), specifically 'Studio route with App Router", have no mention of the same declaration.
If next-sanity MUST be run on the client, it should be explicitly called out in the documentation, and the examples updated to use 'use client' declaration. |
Describe the bug
The issue may be related due to Webpack eagerly resolving modules that aren't used? It seems like sanity exports a bunch of things with barrel exports - is it possible client side code is getting mixed up with server side code perhaps?
The error -
I tried to import defineConfig directly, but couldn't. Interestingly, I did see some folders that seemed related to the error (_createContext, _singletons) -
To Reproduce
Steps to reproduce the behavior:
Here is a slimmed down representation. Normally i wouldn't include everything in the single file, but it makes no difference either way and this is the simplest reproduction of the error -
Expected behavior
Able to embed sanity studio without app crashing.
Which versions of Sanity are you using?
[email protected] (installed today)
@sanity/cli (global) 3.70.0 (up to date)
@sanity/image-url 1.1.0 (up to date)
What operating system are you using?
Windows 10 pro
Which versions of Node.js / npm are you running?
npm - 10.8.3
node - 20.11.1
Additional context
None that I can think of, but happy to help debug / troubleshoot as required to get to the bottom of this.
The text was updated successfully, but these errors were encountered: