Material-ui v4无法为每个组件读取未定义的属性“根”

IT技术 reactjs material-ui
2022-07-21 01:23:24

我已经从Material-UIv3 迁移到 v4。现在,我导入的每个组件都会出现此错误:

app.js:3581 未捕获类型错误:无法读取
未定义的属性“根”

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

app.js:130381 组件出现上述错误:
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": "^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,但每个组件都会出现错误。

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

1个回答

GitHub 中的这条评论解决了这个问题。

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

应该添加到 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

这可能导致了这个问题。