question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReactPlayer not working in React 17 and Next 10

See original GitHub issue

Current Behavior

ReactPlayer is not working with NextJS. I use ReactPlayer to show videos in several formats like mp4 and hls.

At the moment, I am upgrading my dependencies from prior versions to current stable. After updating versions, I get an exception from the console and the page crashes. Versions:

+        "next": "^10.0.6",
+        "react": "^17.0.1",
+        "react-dom": "^17.0.1",
-        "next": "^9.3.6",
-        "react": "^16.12.0",
-        "react-dom": "^16.12.0",

I use the current version of react-player@2.8.2. The error message in the browser console:

> Uncaught undefined
> The above error occurred in one of your React components:
    in Unknown (created by ReactPlayer)
    in Suspense (created by ReactPlayer)
    in div (created by ReactPlayer)
    in ReactPlayer (created by ForwardRef(LoadableComponent))
    in ForwardRef(LoadableComponent) (at VideoPlayer.tsx:77)
    in VideoPlayer (at VideoPlayer.tsx:69)
    in div (created by VideoPlayer__Wrapper)
   [...]

It looks like the problem comes from the React.Suspense Component, so, I switched to next/dynamic import, with no success:

const ReactPlayer = global?.window && dynamic(() => import('react-player/lazy/'), { ssr: false });

Also there is no change if omit the global.window check or the lazy-Package.

Expected Behavior

ReactPlayer should only load client side in NextJS App.

Environment

  • URL attempting to play: URL from our own cdn with mp4 or hls ressource
  • Browser: Chrome@88
  • Operating system: macOS 11

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
lanepartoncommented, Aug 27, 2021

PSA: In case anyone comes across this…

Double checking that react and react-dom are ^17.0.2 solved this for me. I was facing the issues above - importing main or lazy wasn’t working.

5reactions
adarshtcommented, Jul 12, 2021

facing same issue… working fine if i import from react-player/youtube with following version: “react”: “^17.0.0”, “react-player”: “^2.9.0”, Capture

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-player: unable to play just selected item from mapped ...
Replaced the modal outside the map function and it´s holding container and passed modalDate onClick. This code worked for me:
Read more >
react-player - npm
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and ...
Read more >
next js react hydration error - You.com | The Search Engine You ...
in Nextjs react-hydration-error occurs when the SSR content not match in the browser or the the third party library altering the state in...
Read more >
react-player | Yarn - Package Manager
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, ... Not using React? No problem. Migrating to ReactPlayer...
Read more >
Error Boundaries - React
To solve this problem for React users, React 16 introduces a new concept of an “error boundary”. Error boundaries are React components that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found