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

Error building next js app #135

Open
spandres opened this issue Aug 3, 2023 · 6 comments
Open

Error building next js app #135

spandres opened this issue Aug 3, 2023 · 6 comments

Comments

@spandres
Copy link

spandres commented Aug 3, 2023

Problem

I get the following error message after running npm run build:

ReferenceError: window is not defined

Description

I'm importing from a client component ("use client") the wheel component. Unfortunately, the build fails. I verified the problem was the wheel component because after removing it, the build was completed as expected.

I tried the wheel component using the basic setup in the README.

The wheel component works when I run the npm run dev command. The problem is observed only when trying to build the app.

Screenshot 2023-08-02 at 20 21 26
@Gabriel-Passoss
Copy link

Same issue

@spandres
Copy link
Author

spandres commented Aug 7, 2023

My workaround was to create a wrapper component at the layout level.

export default function Wrapper({ children }: {children?: ReactNode}) {
  const [ready, setReady] = useState(false);

  useEffect(() => {
    setReady(true);
  }, []);

  if (!ready) return null;

  return <main>{children}</main>;
}

Just put the wheel component anywhere inside the wrapper, and it should work.

@supramaxis
Copy link

My workaround was to create a wrapper component at the layout level.

export default function Wrapper({ children }: {children?: ReactNode}) {
  const [ready, setReady] = useState(false);

  useEffect(() => {
    setReady(true);
  }, []);

  if (!ready) return null;

  return <main>{children}</main>;
}

Just put the wheel component anywhere inside the wrapper, and it should work.

did not worked for me sadly on nextjs

@berthelol
Copy link

This one worked for me
https://www.npmjs.com/package/react-wheel-of-prizes

@abdulsami822
Copy link

Any update on this issue?

@buivangiang-12148701
Copy link

worked for me:

Modify your import statement for the Wheel component to use Next.js is dynamic imports with ssr set to false. This tells Next.js to only render the component on the client side.

Old: import { Wheel } from 'react-custom-roulette';

Replace:

import dynamic from 'next/dynamic';
const Wheel = dynamic(() => import('react-custom-roulette').then((mod) => mod.Wheel), { ssr: false, });

const WheelOfLuckyGame = (props) => { ... . return ( <Wheel ...../> )}

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

6 participants