nerrood
nerrood

Reputation: 79

WaveSurfer.create is not a function

i'm trying to add WaveSurfer.js to Next.js app.

I imported package by next/dynamic like this

const WaveSurfer = dynamic(() => import('wavesurfer.js'), {ssr: false})

and now when i trying to create new player by WaveSufer.create() i'm getting info that WaveSurfer.create is not a function.

Someone can help me?

Upvotes: 0

Views: 1338

Answers (2)

Alejandro Morales
Alejandro Morales

Reputation: 63

It can be fixed by importing wavesurfer like this:

 const WaveSurfer = (await import("wavesurfer.js")).default;

Upvotes: 1

nerrood
nerrood

Reputation: 79

Instead dynamic import wavesurfer.js i should import a component where wavesurfer.js is used.

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

and then use it as regular component f.ex.

<StyledContainer>
   <DynamicComponent/>
</StyledContainer>

Upvotes: 0

Related Questions