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

Trouble With Webpack #51

Open
homerlex opened this issue Nov 9, 2021 · 3 comments
Open

Trouble With Webpack #51

homerlex opened this issue Nov 9, 2021 · 3 comments

Comments

@homerlex
Copy link

homerlex commented Nov 9, 2021

I'm trying to compile with webpack following the following example:
https://github.com/kbumsik/opus-media-recorder#simple-javascript-example-webpack

I have also added the following to my webpack.config:
https://github.com/kbumsik/opus-media-recorder/tree/master/example/webpack#webpackconfigjs

When I try to compile I get the following errors. Why is it trying to use "fs"?

ERROR in ./node_modules/opus-media-recorder/WebMOpusEncoder.js
Module not found: Error: Can't resolve 'fs' in '/home/project/my-project/node_modules/opus-media-recorder'
 @ ./node_modules/opus-media-recorder/WebMOpusEncoder.js 9:5995-6008
 @ ./node_modules/opus-media-recorder/encoderWorker.js

ERROR in ./node_modules/opus-media-recorder/OggOpusEncoder.js
Module not found: Error: Can't resolve 'fs' in '/home/project/my-project/node_modules/opus-media-recorder'
 @ ./node_modules/opus-media-recorder/OggOpusEncoder.js 9:5995-6008
 @ ./node_modules/opus-media-recorder/encoderWorker.js
@richard-llmnn
Copy link

@homerlex Hey, I think I found a working solution.
Instead of importing .../encoderWorker import import EncoderWorker from '.../encoderWorker.umd
The second part is to pass the MediaRecorder into the EncoderWorker.
Long story short, here are my code:

// my imports
import OpusMediaRecorder from 'opus-media-recorder';
import EncoderWorker from 'worker-loader!opus-media-recorder/encoderWorker.umd';
import OggOpusWasm from 'opus-media-recorder/OggOpusEncoder.wasm';
import WebMOpusWasm from 'opus-media-recorder/WebMOpusEncoder.wasm';

window.MediaRecorder = OpusMediaRecorder;

// and then your function/method that have to use following code
  const media = await navigator.mediaDevices.getUserMedia({audio:true})
  const options = {
      bitsPerSecond: this.bitrate,
      mimeType: "audio/ogg;codecs=opus"
  }
  this.recorder = new MediaRecorder(media, options, {
      encoderWorkerFactory: _ => new EncoderWorker(window.MediaRecorder),
      OggOpusEncoderWasmPath: OggOpusWasm,
      WebMOpusEncoderWasmPath: WebMOpusWasm
  })

I hope I could help you :)

@homerlex
Copy link
Author

Thanks @richard-llmnn - I will try your suggestion when I have the chance.

@kshart
Copy link

kshart commented Apr 11, 2024

Another solution to the problem, add to webpack.config.js

  node: {
      fs: "empty"
  }

For nuxt2, add to nuxt.config.js

  build: {
    extend (config, context) {
      if (context.isClient) {
        config.node = {
          fs: 'empty'
        }
      }
    }
  }

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

3 participants