lottie-react-web 报错: Uncaught TypeError: Cannot read properties of undefined (reading 'forEach') 作者: Chuwen 时间: 2022-10-29 分类: React ## 错误信息 ``` Uncaught TypeError: Cannot read properties of undefined (reading 'forEach') at Lottie2.deRegisterEvents (index.js:226:22) at Lottie2.componentWillUnmount (index.js:148:12) at callComponentWillUnmountWithTimer (react-dom.development.js:20413:14) at HTMLUnknownElement.callCallback2 (react-dom.development.js:3945:14) at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:16) at invokeGuardedCallback (react-dom.development.js:4056:31) at safelyCallComponentWillUnmount (react-dom.development.js:20420:5) at commitUnmount (react-dom.development.js:20951:11) at commitNestedUnmounts (react-dom.development.js:21004:5) at unmountHostComponents (react-dom.development.js:21290:7) ``` ![](https://cdn.nowtime.cc/2022/10/29/580616896.png) ## 问题原因 查看报错信息,似乎指的是 `eventListeners` 变量不是一个数组或不存在 ![](https://cdn.nowtime.cc/2022/10/29/92600442.png) ## 解决方案 加上这个属性并给一个空数组即可 `eventListeners` ```react ``` ![](https://cdn.nowtime.cc/2022/10/29/1407110091.png) 标签: React, Lottie