简体   繁体   中英

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

In the npm console , everything is okay:

在此处输入图片说明

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');

在此处输入图片说明

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 .

Change your check to

if(node && node.type === 'file'){
    ...
}

您可能正在浏览器中运行源文件,而不是已构建的文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM