devcshort / react-hls

Simple React component for playing hls/rtmp live streams.
https://www.npmjs.com/package/react-hls-player
MIT License
118 stars 48 forks source link

ReferenceError: window is not defined #20

Closed vkhanh74 closed 3 years ago

vkhanh74 commented 3 years ago

I using react-hls lib with next.js but when i import lib in component it throw an error: ReferenceError: window is not defined

devcshort commented 3 years ago

I using react-hls lib with next.js but when i import lib in component it throw an error: ReferenceError: window is not defined

This package isn't able to be rendered server side, due to the underlying Javascript library being used. However, you can use Next.js Dynamic Import with SSR disabled to use this component in a Next.js app. See example below.

import dynamic from 'next/dynamic';

const HlsPlayerWithNoSSR = dynamic(
  () => import('react-hls-player'),
  { ssr: false }
);

function MyVideoComponent() {
  return (
    <div>
      <HlsPlayerWithNoSSR autoplay />
    </div>
  );
}
devcshort commented 3 years ago

Did this work for you @vkhanh74 ?

gosuwtf commented 3 years ago

This worked for me with Next.js @devcshort

devcshort commented 3 years ago

This worked for me with Next.js @devcshort

Thanks @natelook

@vkhanh74 I'm going to close this for now. Feel free to re-open if you are still having issues.