0

I am trying to use the npm react-wavesurfer package, but get the error

this._wavesurfer.init is not a function

This seems to be because wavesurfer is not set up properly. The "Prereqs and common pitfalls" page on the github states that "WaveSurfer needs to be a globall accessible variable."

// provide WaveSurfer as a globally accessible variable
  plugins: [
    new webpack.ProvidePlugin({
      WaveSurfer: 'wavesurfer.js'
    })
  ],
  // Alias `wavesurfer` to the correct wavesurfer package.
  // (wavesurfer.js has some non-standard naming convention)
  resolve: {
    alias: {
      wavesurfer: require.resolve('wavesurfer.js')
    }
  },

My react project was created with create-react-app so I don't have a webpack config file. How can I include these wavesurfer plugins?

Note: This question asks the same thing but the only answer is to use the non-react, wavesurfer.js package directly. I would prefer to use react-wavesurfer.

David Ferris
  • 2,215
  • 6
  • 28
  • 53
  • Well it looks like you gotta add custom `webpack.config.js` parameters, which I don't think you can do out of the box in `create-react-app`. If you Google around there's some tools you can use to work around this, but a simpler way might just be to download the relevant `wavesurfer.js` files you need and include them in the `

    ` of you `index.html`, so they're all loaded before you actual app loads and thus available globally

    – Jayce444 Dec 05 '19 at 01:31
  • Though to be honest, it seems there's been a bunch of changes and new versions since the `react-wavesurfer` stopped being supported, so might not be a bad idea to just use the non-React one – Jayce444 Dec 05 '19 at 01:32

0 Answers0