react-hls icon indicating copy to clipboard operation
react-hls copied to clipboard

import error

Open colindotfun opened this issue 4 years ago • 15 comments
trafficstars

trying to run the very basic example:

  const renderHlsPlayer = () => {
    return (
      <ReactHlsPlayer
        playerRef={null}
        src="https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8"
        autoPlay={false}
        controls={true}
        width="100%"
        height="auto"
      />
    );
  };

and getting this error 🤔

image

colindotfun avatar Jun 10 '21 21:06 colindotfun

Are you using import or require? And are you using the latest create-react-app template or a custom build process? Can you provide any additional info that may help out about your project?

I think there may be an issue with the way I'm currently building the package.

devcshort avatar Jun 10 '21 22:06 devcshort

I'm using Typescript with Next.js.

This import code runs on the client:

import ReactHlsPlayer from "react-hls-player";

In case it helps, the actual HLS package runs fine imported this way:

import Hls from "hls.js"

colindotfun avatar Jun 10 '21 23:06 colindotfun

Here's a minimal StackBlitz example: https://stackblitz.com/edit/nextjs-bgkcxa?devtoolsheight=33&file=pages/index.js

image

colindotfun avatar Jun 10 '21 23:06 colindotfun

Thanks @colinricardo I think I may have found the issue. Going to test it out in a create-react-app and create-next-app to see

devcshort avatar Jun 11 '21 00:06 devcshort

Alright, the issue is going to be a bit more than I'm able to get to at the moment. I'd recommend using version 2.0.0 or 1.1.0 in the meantime. I think I'm going to need to introduce a proper bundler for this. In version 3 I was hoping to shed off some of the heavy configurations needed with webpack and what not, and I'm pretty sure getting rid of webpack is what's causing this issue.

Thanks for bringing this too my attention

devcshort avatar Jun 11 '21 00:06 devcshort

Great, thanks! I'll try one of those versions. Let me know if I can help with anything :)

colindotfun avatar Jun 11 '21 09:06 colindotfun

Version 2.0.0 working great, thanks!

colindotfun avatar Jun 11 '21 14:06 colindotfun

Great, thanks! I'll try one of those versions. Let me know if I can help with anything :)

If you're familiar with creating react packages with typescript and might be able to point me in the right direction that'd be helpful. I'm reading through some articles trying to figure out the best way for compatibility.

devcshort avatar Jun 11 '21 17:06 devcshort

React +Nextjs latest version + react-hls latest = Not working: import error..

ioram-devi avatar Jul 25 '21 00:07 ioram-devi

Same here

jannisringwald avatar Aug 09 '21 16:08 jannisringwald

@yuri-devi @iMJumpmxn I'm not sure when I'll get a chance to look in to this. In the meantime, you should be able to npm install [email protected]. There were some api changes between v2 and v3, but nothing too drastic.

devcshort avatar Aug 09 '21 22:08 devcshort

Same issue here, using dynamic import solved.

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

tgwow avatar Sep 14 '21 00:09 tgwow

@tgwow I was thinking this may be the case, but haven't had the time to look in to it. Thanks for sharing!

devcshort avatar Sep 14 '21 17:09 devcshort

Same issue here, using dynamic import solved.

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

Using Dynamic import in Next.js helped 😃

vhalllive avatar Jan 19 '22 07:01 vhalllive

Same issue here, using dynamic import solved.

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

@tgwow thanks for sharing this Dynamic Import Solved my build issue

Kelechiokpani avatar May 30 '24 08:05 Kelechiokpani