react-media-recorder icon indicating copy to clipboard operation
react-media-recorder copied to clipboard

ReferenceError: Worker is not defined

Open Riezmann opened this issue 1 year ago • 13 comments

Hi, I have recently tried to use this package in react 18, but I got an error called "Worker is not defined".

Here is the package.json: [...] "dependencies": { "next": "12.2.3", "react": "18.2.0", "react-dom": "18.2.0", "react-icons": "^4.4.0", "react-media-recorder": "^1.6.6" }, "devDependencies": { "@types/node": "18.6.3", "@types/react": "18.0.15", "@types/react-dom": "18.0.6", "eslint": "8.21.0", "eslint-config-next": "12.2.3", "typescript": "4.7.4" } } And the element I put the record in is:

    <p>{status}</p>

    <button onClick={startRecording}>Start Recording</button>

    <button onClick={stopRecording}>Stop Recording</button>

    <video src={mediaBlobUrl} controls autoPlay loop />

Riezmann avatar Aug 07 '22 13:08 Riezmann

Any solution?

durdenx avatar Feb 08 '23 11:02 durdenx

Error also exists on my end. Here's package.json dependencies. I'm using Nextjs with React 18

{
    "@emotion/react": "^11.10.6",
    "@emotion/styled": "^11.10.6",
    "@mui/icons-material": "^5.11.11",
    "@mui/lab": "^5.0.0-alpha.124",
    "@mui/material": "^5.11.15",
    "axios": "^1.3.4",
    "eslint": "8.37.0",
    "eslint-config-next": "13.2.4",
    "next": "13.2.4",
    "prop-types": "^15.8.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-media-recorder": "^1.6.6",
    "styled-components": "^5.3.9",
    "uuid": "^9.0.0",
    "zustand": "^4.3.7"
  }

iisalazar avatar Apr 01 '23 14:04 iisalazar

try this in nextjs:

const ReactMediaRecorder = dynamic(() => import('react-media-recorder').then((mod) => mod.ReactMediaRecorder), {
  ssr: false,
});

danielwii avatar Apr 16 '23 10:04 danielwii

ReferenceError: dynamic is not defined getting this error in next js. Any help on this?

609harsh avatar Jul 15 '23 13:07 609harsh

ReferenceError: dynamic is not defined getting this error in next js. Any help on this?

need to import dynamic from "next/dynamic".

import dynamic from "next/dynamic";

MrJooka avatar Jul 21 '23 09:07 MrJooka

try this in nextjs:

const ReactMediaRecorder = dynamic(() => import('react-media-recorder').then((mod) => mod.ReactMediaRecorder), {
  ssr: false,
});

then how we can import this useReactMediaRecorder hook if we get the same error

shashi2602 avatar Sep 11 '23 13:09 shashi2602

Here is my solution for hooks related to useReactMediaRecorder or class-base too:

Assume we have a custom component called CustomMediaRecorder that uses useReactMediaRecorder. We want to use this component in the current component.

 const CustomMediaRecorder = dynamic(
  () => import('..../CustomMediaRecorder'),
  {
    ssr: false,
  }
);

NB. CustomMediaRecorder can be a class-based or functional component. Import it into your current component like the code snippet above shows.

kabtamu-degifie avatar Oct 04 '23 08:10 kabtamu-degifie

what is the solution for Remix based projects?

rorlich avatar Jan 02 '24 10:01 rorlich

@rorlich since the workaround seems to exclude the part from rendering on server side, you can use the client side rendering of Remix. See here https://remix.run/resources/remix-utils#clientonly

iwan933 avatar Jan 30 '24 12:01 iwan933

got it, thanks

On Tue, Jan 30, 2024 at 2:39 PM iwan933 @.***> wrote:

@rorlich https://github.com/rorlich since the workaround seems to exclude the part from rendering on server side, you can use the client side rendering of Remix. See here https://remix.run/resources/remix-utils#clientonly

— Reply to this email directly, view it on GitHub https://github.com/DeltaCircuit/react-media-recorder/issues/107#issuecomment-1916757786, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEGVOYWSNN2XQ2JMCFUEX3YRDSY5AVCNFSM552PJ6LKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJRGY3TKNZXHA3A . You are receiving this because you were mentioned.Message ID: @.***>

rorlich avatar Jan 30 '24 14:01 rorlich

How do we get the hook? useMediaRecorder? I am trying to do it with below code to set the state. But it never works. Any suggestions?

useEffect(() => { import("..").then((module) => { const { useReactMediaRecorder } = module; setUseMediaRecorder(useReactMediaRecorder); }); }, []);

kubi-ozisik avatar Apr 14 '24 21:04 kubi-ozisik