使用npm包“extendable-media-recorder-wav-encoder”时未定义Nextjs:Blob

nbysray5  于 2023-03-08  发布在  其他
关注(0)|答案(1)|浏览(101)

我正在使用这个包If I import normally it works fine but I'm getting Blob is not defined since its Nextjs中的“connect”函数
因此,我尝试动态导入它,如下Here I'm getting type error
Argument of type '() => Promise<(port: globalThis.MessagePort) => Promise>' is not assignable to parameter of type 'DynamicOptions | Loader'.
然后尝试匹配类型enter image description here
但现在函数不可调用enter image description here
这个包使用了Blob,由于SSR的原因,它的show Blob没有定义,如何解决这个问题?

hjqgdpho

hjqgdpho1#

我不是Next.js用户,但我猜dynamic()只适用于组件。
但是connect()返回一个promise,这意味着您可以用普通的import()替换静态导入。

const connect = () => import('extendable-media-recorder-wav-encoder')
    .then(({ connect }) => connect())

只要确保connect()不会在服务器上被调用。

相关问题