我已从Material-UI
v3迁移到v4。现在对于我导入的每个组件都会显示此错误:
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
<WithStyles(ForwardRef(Button))> 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更新为guide说:
"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_modules
和yarn.lock
并尝试了yarn
,但每个组件都显示错误。
也找到了这个issue,但没有找到任何解决方案...
答案 0 :(得分:0)
GitHub中的comment解决了该问题。
"hoist-non-react-statics": "^3.3.0",
应添加到package.json
如here
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
这可能是导致此问题的原因。