Material-ui v4无法读取每个组件的undefined属性"root" [英] Material-ui v4 Cannot read property 'root' of undefined for every component

查看:137
本文介绍了Material-ui v4无法读取每个组件的undefined属性"root"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从Material-UI v3迁移到v4.现在对于我导入的每个组件都会显示此错误:

I've migrated from Material-UI v3 to v4.now this error shows up for every component I import:

app.js:3581未捕获的TypeError:无法读取属性
不确定的根"

app.js:3581 Uncaught TypeError: Cannot read property
'root' of undefined

在按钮上(app.js:3581)
在renderWithHooks(app.js:126202)
在updateForwardRef(app.js:127721)
在beginWork(app.js:128925)
在performUnitOfWork(app.js:132576)
在workLoop(app.js:132616)

at Button (app.js:3581)
at renderWithHooks (app.js:126202)
at updateForwardRef (app.js:127721)
at beginWork (app.js:128925)
at performUnitOfWork (app.js:132576)
at workLoop (app.js:132616)

app.js:130381上面的错误发生在组件中:
在WithStyles(ForwardRef(Button))中(由Rtl创建)
在StylesProvider中(由Rtl创建)
在Rtl中(由App创建)
在提供程序中(由App创建)
在应用程序中

app.js:130381 The above error occurred in the component:
in WithStyles(ForwardRef(Button)) (created by Rtl)
in StylesProvider (created by Rtl)
in Rtl (created by App)
in Provider (created by App)
in App

React和react-dom更新为指南说:

React and react-dom are updated as guide said:

"react": "^16.8.6",
"react-dom": "^16.8.6",
"@material-ui/core": "^4.0.0-rc.0",
"@material-ui/styles": "^4.0.0-rc.0",

我删除了/node_modulesyarn.lock并尝试了yarn,但是每个组件都显示错误.

I've removed /node_modules and yarn.lock and tried yarn but error shows up for every component.

也找到了这个问题,但没有任何解决方案...

Also found this issue but not any solution...

推荐答案

应添加到package.json

should be added to package.json

,并如所述此处

npm ls hoist-non-react-statics

将得到

├─┬ @material-ui/core@3.9.3
│ └── hoist-non-react-statics@3.3.0 
├─┬ material-ui@0.20.2
│ └─┬ recompose@0.26.0
│   └── hoist-non-react-statics@2.5.5  deduped
├─┬ react-hot-loader@4.12.0
│ └── hoist-non-react-statics@3.3.0 
├─┬ react-jss@8.6.1
│ └── hoist-non-react-statics@2.5.5 
├─┬ react-redux@7.1.0
│ └── hoist-non-react-statics@3.3.0 
├─┬ react-router@3.2.3
│ └── hoist-non-react-statics@2.5.5  deduped
└─┬ recompose@0.30.0
  └── hoist-non-react-statics@2.5.5  deduped

这可能是导致此问题的原因.

which is probably causing this issue.

这篇关于Material-ui v4无法读取每个组件的undefined属性"root"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆