突然间,我的整个构建崩溃了,无法构建。几天前,我使用新的 create-react 应用程序构建重置了项目,暂时还好,然后昨天 - 类似的问题,但出现了不同的错误:
Failed to compile.
TS2322: Type '{ children: Element; xsDown: true; }' is not assignable to type 'IntrinsicAttributes & HiddenProps'.
Property 'children' does not exist on type 'IntrinsicAttributes & HiddenProps'.
208 | {studentName(x)} <{x.student}>
209 | </Box>
> 210 | {!locked && <Hidden xsDown={true}><Box><RemoveButton deleteClickHandler={deleteClickHandler} x={x}/></Box></Hidden>}
| ^^^^^^
211 | {locked &&
212 | <Box>
213 | <Tooltip title="Locked"><Lock/></Tooltip>
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我已经删除了一些我在小地方使用的库,我怀疑这些库会导致类型声明冲突,但是,我仍然遇到这个问题,此时,我完全陷入困境。
Package.json 并不是很复杂:
"name": "****Redacted****",
"version": "1.2.0",
"private": true,
"dependencies": {
"@date-io/date-fns": "^1.3.13",
"@fortawesome/fontawesome-common-types": "^6.1.1",
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-brands-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.1.18",
"@material-table/core": "^4.3.39",
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.3",
"@sentry/react": "^6.19.6",
"@sentry/tracing": "^6.19.6",
"@stripe/react-stripe-js": "^1.7.0",
"@stripe/stripe-js": "^1.26.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.2.1",
"@types/dateformat": "^5.0.0",
"@types/jest": "^27.0.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react-router-dom": "^5.3.3",
"amazon-cognito-identity-js": "^5.2.8",
"amazon-cognito-identity-js-typescript": "^1.22.0",
"axios": "^0.26.1",
"dateformat": "^4.6.3",
"immutability-helper": "^3.1.1",
"react": "^18.0.0",
"react-dnd": "^14.0.5",
"react-dnd-html5-backend": "14.1.0",
"react-dnd-touch-backend": "14.1.0",
"react-dom": "^18.0.0",
"react-router": "^6.3.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.0",
"sass": "^1.49.11",
"typescript": "^4.6.3",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "GENERATE_SOURCEMAP=false react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {}
}
最佳答案
我相信这是因为您已更新到 React 18(具体来说, "@types/react": "^18.0.0",
)。
This pull request谈论发生了什么变化。
由于问题源于 Material Ui 4 组件,因此您很可能需要执行以下操作之一:
- 升级到 Mui5
- 降级到 React 17
- 等待this PR进行合并,这似乎可以缓解您遇到的问题。
(此外,<Hidden/>
来自 MUI4 does implement 带有 children?: React.ReactNode;
的 child ,就像第一个链接提到的那样)
关于reactjs - React、Typescript 和 Material-UI 4 的编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71810438/