ReactPlayer not working in React 17 and Next 10
See original GitHub issueCurrent 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:
- Created 3 years ago
- Reactions:13
- Comments:13 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
facing same issue… working fine if i import from react-player/youtube with following version: “react”: “^17.0.0”, “react-player”: “^2.9.0”,