Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Application Error with Remix v2? #1690

Closed
genmon opened this issue Oct 12, 2023 · 9 comments
Closed

Application Error with Remix v2? #1690

genmon opened this issue Oct 12, 2023 · 9 comments

Comments

@genmon
Copy link

genmon commented Oct 12, 2023

Current Behavior

Using ReactPlayer with Remix v2 out of the box triggers an Application Error:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Expected Behavior

I would expect the player to appear, as it did in Remix v1.

Steps to Reproduce

I have a minimal repro here: remix-v2-reactplayer-minimal

This is the stock Remix v2 starter template

Other Information

I am not experienced with Remix v2 so it is possible I am missing something obvious. Would be grateful if anyone else could let me know whether I'm seeing an incompatibility, or if it's a setup problem.

@genmon
Copy link
Author

genmon commented Oct 12, 2023

A colleague has provided me with a workaround:

// @ts-ignore bundling issue with react-player
const Player = ReactPlayer.default as typeof ReactPlayer;

A bundling problem, perhaps similar to #193 from 2017? I'll leave this issue open as it may connect to something else.

@tb-b
Copy link

tb-b commented Oct 27, 2023

I'm running into the same issue on Remix 2.1.0

@UncleGravity
Copy link

Same issue here, I'm working around it by using ReactPlayer.default, which makes typescript unhappy.

@dev-xo
Copy link

dev-xo commented Nov 4, 2023

This made it for me, also typescript it's happy about it:

import { useState } from 'react'

import ReactPlayer from 'react-player'
import Example_Video from '~/public/media/example-video.mov'

const Player = ReactPlayer.default

export function Video() {
  const [hasVideoLoaded, setHasIsVideoLoaded] = useState(false)

  return (
    <div className={`${hasVideoLoaded ? 'opacity-100' : 'opacity-0'} transition`}>
      <Player
        url={Example_Video}
        playing={true}
        muted={true}
        playsinline={true}
        onReady={() => setHasIsVideoLoaded(true)}
      />
    </div>
  )
}

Thanks to @genmon about the insights on it!

@Varkoff
Copy link

Varkoff commented Dec 4, 2023

Same issue here. I tried your fix @dev-xo but there is a type error on the line const Player = ReactPlayer.default (property does not exist).

import ReactPlayer from 'react-player/youtube' works perfectly. But it doesn't work for Vimeo, for instance.

@bartling-cce
Copy link

bartling-cce commented Jan 7, 2024

A colleague has provided me with a workaround:

// @ts-ignore bundling issue with react-player
const Player = ReactPlayer.default as typeof ReactPlayer;

A bundling problem, perhaps similar to #193 from 2017? I'll leave this issue open as it may connect to something else.

This issue is still present in Remix 2.4.1. We just switched to ESM module support and that switch demonstrated this issue. Using the above suggestion fixed our issue.

@SchattenGestalt
Copy link

SchattenGestalt commented Jan 15, 2024

You saved my day. I was looking for a solution for days!!!

EDIT: Well. The solution helped in the first place, but when I refresh the page I get a slightly different error.

Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

@goldcaddy77
Copy link

You can fix this with Client Only from remix-tools.

react-player.client.tsx:

import ReactPlayer from "react-player";
export default ReactPlayer;

video-player.tsx:

import { ClientOnly } from "~/components/client-only";
import ReactPlayer from "~/components/react-player.client";

export function VideoPlayer() {
  return (
      <ClientOnly fallback={<div>Video</div>}>
        {() => <ReactPlayer url={url} />}
      </ClientOnly>
  );
}

@SchattenGestalt
Copy link

SchattenGestalt commented Feb 28, 2024

@goldcaddy77 Thx for your comment.
That is, what I have finally done, but didn't mentioned it here.

Repository owner locked and limited conversation to collaborators Apr 19, 2024
@luwes luwes converted this issue into discussion #1803 Apr 19, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants