简体   繁体   English

TypeError:无法解构“undefined”的属性“reflectionId”,因为它是未定义的

[英]TypeError: Cannot destructure property 'reflectionId' of 'undefined' as it is undefined

I have a deeply nested object and I'm trying to get a specific value from it.我有一个深度嵌套的 object,我正试图从中获取特定值。 On my development and production environment, the function returns the error above (TypeError: Cannot destructure property 'reflectionId' of 'undefined' as it is undefined.) However, I am unable to debug this, and when I put in the exact same object and function into a code sandbox, it works fine .在我的开发和生产环境中,function 返回上面的错误(TypeError: Cannot destructure property 'reflectionId' of 'undefined' as it is undefined.)但是,我无法调试它,当我输入完全相同的 object和 function 进入代码沙箱,它工作正常

I have recreated my object and code in a codesandbox here: https://codesandbox.io/s/nameless-bird-rknxrr?file=/src/index.js:28281-28461 (check the console to see the working output)我在此处的代码箱中重新创建了我的 object 和代码: https://codesandbox.io/s/nameless-bird-rknxrr?file=/src/index.js:28281-28461 (检查控制台以查看工作输出)

const discordLink = CHARACTER_MAP
  .flatMap((character) => character.chapters)
  .find(({ reflectionId }) => reflectionId === reflectionNum).discordLink;

What could the problem be?可能是什么问题? The flatMap returns a properly formatted object (checked that). flatMap 返回格式正确的 object(已检查)。 reflectionId is the property name I am looking for, and it seems correctly defined in both my live code and the sandbox. reflectionId是我正在寻找的属性名称,它似乎在我的实时代码和沙箱中都正确定义了。 Based on how.find() is described in [the Mozilla docs] 1 it seems like I'm using the "Using arrow function and destructuring" method properly too.根据 [Mozilla 文档] 1中描述的 how.find() ,我似乎也在正确使用“使用箭头 function 和解构”方法。 It's most puzzling that it works in codesandbox but not in live.最令人费解的是,它在 codesandbox 中有效,但在 live 中无效。

错误信息

Try this:尝试这个:

const discordLink = CHARACTER_MAP
  .flatMap((character) => character.chapters)
  .find((reflection) => reflection.reflectionId === reflectionNum).discordLink

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无法解构“未定义”的属性“位置”,因为它未定义 - TypeError: Cannot destructure property 'position' of 'undefined' as it is undefined TypeError:无法解构“对象(...)(...)”的属性“用户”,因为它未定义 - TypeError: Cannot destructure property 'user' of 'Object(...)(...)' as it is undefined × TypeError:无法解构'Object(...)(...)'的属性'currentUser',因为它是未定义的 - × TypeError: Cannot destructure property 'currentUser' of 'Object(...)(...)' as it is undefined TypeError:无法解构“thunkAPI”的属性“rejectWithValue”,因为它未定义 - TypeError: Cannot destructure property 'rejectWithValue' of 'thunkAPI' as it is undefined 类型错误:无法解构“项目”的属性“名称”,因为它未定义 - TypeError: Cannot destructure property 'name' of 'item' as it is undefined TypeError:无法解构“Jt”的属性“eligibleURLPatterns”,因为它未定义 - TypeError: Cannot destructure property 'eligibleURLPatterns' of 'Jt' as it is undefined TypeError:无法解构“未定义”或“空”的属性“stat” - TypeError: Cannot destructure property `stat` of 'undefined' or 'null' TypeError:无法解构“orderPay”的属性“加载”,因为它未定义 - TypeError: Cannot destructure property 'loading' of 'orderPay' as it is undefined TypeError:无法解构“未定义”或“空”的属性“queryResult” - TypeError: Cannot destructure property `queryResult` of 'undefined' or 'null' TypeError:无法解构“userUpdate”的属性“加载”,因为它未定义 - TypeError: Cannot destructure property 'loading' of 'userUpdate' as it is undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM