[英]ReactJS TypeError: Cannot read property of undefined
I have this code right here, that works in this online text editor: https://codesandbox.io/s/o4n0v203vy 我在这里有此代码,可在此在线文本编辑器中使用: https : //codesandbox.io/s/o4n0v203vy
In the npm console , everything is okay: 在npm控制台中 ,一切正常:
But in the browser , this happens: 但是在浏览器中 ,会发生这种情况:
What logs in the console, when i do export var renderTree = (node, setActiveNode, activeNode) => { console.log(node && node.type, 'look here');
当我
export var renderTree = (node, setActiveNode, activeNode) => { console.log(node && node.type, 'look here');
I can't figure out why is this happening. 我不知道为什么会这样。 Any help is appreciated!
任何帮助表示赞赏! Thanks!
谢谢!
The variable node
is undefined
so doesn't have a property called type
. 变量
node
是undefined
因此没有名为type
的属性。
Change your check to 将支票更改为
if(node && node.type === 'file'){
...
}
您可能正在浏览器中运行源文件,而不是已构建的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.