Skip to content
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

ReferenceError: Worker is not defined #107

Open
Riezmann opened this issue Aug 7, 2022 · 17 comments
Open

ReferenceError: Worker is not defined #107

Riezmann opened this issue Aug 7, 2022 · 17 comments

Comments

@Riezmann
Copy link

Riezmann commented Aug 7, 2022

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 />
@durdenx
Copy link

durdenx commented Feb 8, 2023

Any solution?

@iisalazar
Copy link

iisalazar commented Apr 1, 2023

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"
  }

@danielwii
Copy link

try this in nextjs:

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

@609harsh
Copy link

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

@MrJooka
Copy link

MrJooka commented Jul 21, 2023

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";

@shashi2602
Copy link

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

@kabtamu-degifie
Copy link

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.

@rorlich
Copy link

rorlich commented Jan 2, 2024

what is the solution for Remix based projects?

@iwan933
Copy link

iwan933 commented Jan 30, 2024

@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

@rorlich
Copy link

rorlich commented Jan 30, 2024 via email

@kubi-ozisik
Copy link

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); }); }, []);

@ChenAlmost
Copy link

ChenAlmost commented May 22, 2024

I solve this problem by dynamic import the component A containing useMediaRecorder

const componentA = dynamic(() => import('@/components/a').then((mod) => mod.default), { ssr: false, });

@gamrom
Copy link

gamrom commented Jun 17, 2024

add
'use client'

top of the component.
Is it solve?

@lagupa
Copy link

lagupa commented Aug 10, 2024

add 'use client'

top of the component. Is it solve?

That did the trick for me...😃

@robbinzoomers
Copy link

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); }); }, []);

Does anyone has this working in NextJS and has an example of it? I'm getting an Unhandled Runtime Error. 🙁 I can get the react-media-recorder working in my local environment, but every time I'm deploying to Vercel it fails.

@amirmahdioun
Copy link

amirmahdioun commented Oct 5, 2024

same error with nextjs
worker is not defined error on build

@hdrabs
Copy link

hdrabs commented Nov 10, 2024

I am using NextJS 14.1.1.

What I did was created a separate component for AudioRecording named AudioRecording.tsx having 'use client' on the top.

Imported this component dynamically

import dynamic from "next/dynamic";

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

And used it like

<AudioRecorder
  onRecordingComplete={(file) =>
    // my state update
  }
  isRecording={false}
/>

and I got it to work without giving build time errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests