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

NextJS Server-side Rendering bug / docs error #1093

Open
1 of 2 tasks
JonnyDawe opened this issue Feb 26, 2024 · 4 comments
Open
1 of 2 tasks

NextJS Server-side Rendering bug / docs error #1093

JonnyDawe opened this issue Feb 26, 2024 · 4 comments
Labels
bug Something isn't working triage New issues that needs consideration

Comments

@JonnyDawe
Copy link

Bug report

Packages affected

  • sandpack-client
  • sandpack-react

Description of the problem

I am trying to use Sandpack with NextJS. Following the documentation exactly as seen in the docs here I get this error: TypeError: (0 , react__WEBPACK_IMPORTED_MODULE_1__.createContext) is not a function.

The example repo implementation is different from the documentation example and places Sandpack in a "use client" component.

I'm presuming the documentation in this case is incorrect and it is not possible to use Sandpack in a React Server Component?

What were you doing when the problem occurred?

I exactly replicated the documentation, copying over code snippets.

This code causes the error.

import { Sandpack } from "@codesandbox/sandpack-react";
 
export default function Home() {
  return (
    <div>
      <Sandpack theme="dark" />
    </div>
  );
}

What steps can we take to reproduce the problem?

Take the app directory example repo for nextjs and copy in the above snippet to the home page.tsx file.

Your Environment

Software Name/Version
Sandpack-client version "2.13.2"
Sandpack-react version "2.13.2"
Browser chrome
Operating System macOS
@JonnyDawe JonnyDawe added bug Something isn't working triage New issues that needs consideration labels Feb 26, 2024
@fuadinadhif
Copy link

Do you find the solution? I face the exact same problem.

@fuadinadhif
Copy link

I found the solution. We need to render Sandpack in client side, so use "use client" in the intended file. Sandpack actually has an extensive examples in this repository https://github.com/codesandbox/sandpack/tree/main/examples/

@mauriciorossdev
Copy link

I found the solution. We need to render Sandpack in client side, so use "use client" in the intended file. Sandpack actually has an extensive examples in this repository https://github.com/codesandbox/sandpack/tree/main/examples/

Hello! I was having similar problems, but I ran into this error that does not let me move forward, I used the example of next js app dir, but I had no success, could you tell a little more about how you solved it? maybe it is a matter of version of next js and react?

Here is the error in question: TypeError:
Cannot read properties of null (reading 'useState')

@fuadinadhif
Copy link

I found the solution. We need to render Sandpack in client side, so use "use client" in the intended file. Sandpack actually has an extensive examples in this repository https://github.com/codesandbox/sandpack/tree/main/examples/

Hello! I was having similar problems, but I ran into this error that does not let me move forward, I used the example of next js app dir, but I had no success, could you tell a little more about how you solved it? maybe it is a matter of version of next js and react?

Here is the error in question: TypeError: Cannot read properties of null (reading 'useState')

Based on the error message you provided. I suspect the error is not within the Sandpack package but in your own code. Maybe you try to read the value of useState but never defined it first/it contains null value without using optional chaining?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that needs consideration
Projects
None yet
Development

No branches or pull requests

3 participants