Material-ui v4 Cannot read property 'root' of undefined for every component

我的未来我决定 提交于 2020-04-18 07:10:07

问题


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

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

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 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 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",

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...


回答1:


this comment in GitHub solved the problem.

 "hoist-non-react-statics": "^3.3.0",

should be added to package.json

and as said here

npm ls hoist-non-react-statics

will result

├─┬ @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.



来源:https://stackoverflow.com/questions/56574417/material-ui-v4-cannot-read-property-root-of-undefined-for-every-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!