-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
import ReactPlayer from 'react-player/lazy' fails with vite #1443
Comments
It seems like my implementation of lazy loading players is prone to errors. I am open to better suggestions. Would it be better to just have a component that accepts a import ReactPlayerCustom from 'react-player/custom'
import Youtube from 'react-player/youtube'
import Facebook from 'react-player/facebook'
<ReactPlayerCustom players={[Youtube, Facebook]} etc etc /> |
I think the current api is good. I have an app where a user can enter any video url so it would be good if react player could automatically figure out which player to load (like it's doing now) since I can't know in advance. If I have time today, maybe I can figure out what the actual cause of the error is and open a PR. |
@cookpete That looks great. We import everything cause of that problem, but only use |
@cmaerz I have to ask… why not just use |
@cookpete We mostly play radio streams i guess that mostly uses either just the file player or the hls player. I had problems with just importing the file player, but tbh I don't really know why. |
@cookpete Haven't had time to write a fix but I think the issue is that vite uses native ESM imports whereas ReactPlayer appears to use ESM in the source code but exports CommonJS in the npm package. So I think just adding an untransformed ESM version to the npm package would fix the bug. |
If it may help, problem stems from dynamic imports of players/index
A workaround would be e.g to pretty much what does
This feels a lot intrusive in source code so I guess an esm export would be preferrable (as @DouglasDev suggested)? |
We are also facing the same issue with Vite in dev (esbuild). I think an ESM export would be the best way forward too. |
I'm getting the same error. Anyone with a solution? |
I'm still having this issue using React Player in an app that builds with Vite. App crashes in dev but works in production using react-player/lazy. Is there a workaround for this? |
Hi @cookpete! Do you think we could reopen this issue (at least for clarity sake)? Thank you so much! |
I also have this issue. For now, we're not using |
Would using |
Maybe it's a little bit too late but in my case the import of lazy component throw general error about not found the start template. I realizied the solution:
}
I've used node 20.x, vite 5.0, react 18.2, react-player 2.16.0, together with the Laravel / Inertia stack. Hope this would help someone. |
this should be fixed in v3.0.0-canary.3 note that this version has only ESM builds for now, we are testing if CJS or IIFE is actually still needed. |
@luwes any idea why my import/linter shows an error after updating to v3.0.0-canary.3?
ESLint: Unable to resolve path to module 'react-player/ lazy'.(import/ no-unresolved) |
Current Behavior
The app crashes with the following error:
Expected Behavior
I expect the video to load
Steps to Reproduce
npm i
npm run dev
Environment
The text was updated successfully, but these errors were encountered: