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

ReferenceError: navigator is not defined

Open doverradio opened this issue 4 years ago • 1 comments

Hello,

I came across your library and wanted to test drive it in my app. However, after installing and running, I got this error:

Module../node_modules/react-audio-recorder/dist/getUserMedia.js
./node_modules/react-audio-recorder/dist/getUserMedia.js:1
> 1 | export default navigator.mediaDevices ?
  2 |     navigator.mediaDevices.getUserMedia :
  3 |     (navigator.getUserMedia ||
  4 |         navigator.webkitGetUserMedia ||```

Is there a solution for this?

I'm running it in next.js

doverradio avatar Apr 24 '20 17:04 doverradio

Hello there,

Next.js runs all import files server side. You can use dynamic import to get around this problem. Dynamic Import - Next.js

For example:

import dynamic from 'next/dynamic'

const AudioRecorder = dynamic(
  () => import('react-audio-recorder'),
  { ssr: false }
)

ozdemiremrah avatar Nov 10 '21 19:11 ozdemiremrah