You need to enable JavaScript to run this app.
导航

uni-app 编译报错 TypeError: Converting circular structure to JSON

最近更新时间2022.08.17 20:40:40

首次发布时间2022.08.17 20:40:40

问题描述

使用 uni-app 框架进行开发,编译到微信小程序端时出现如下报错:

alt

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'n'
    |     property '_events' -> object with constructor 'n'
    |     property '@room/client-banned' -> object with constructor 'r'
    --- property 'context' closes the circle
    at JSON.stringify (<anonymous>)
    at cloneWithData (vender.js?178:8572)

问题解答

mp.runtime.esm.js 中的 cloneWithData,对 vue 的 data 序列化使用的序列化方法为 JSON.parse(JSON.stringify()) 。如果在 vue 组件的 data 里挂载 RTC 实例,由于实例继承了 EventEmitter3 对象,因此无法通过上述方法序列化。
建议将 RTC 实例挂载到 vuex 的 store 里。