我正在构建一个前端页面,我需要@material-ui/lab。使用npm安装包后,我在编译时得到一个typescript错误:TS2307: Cannot find module '@material-ui/lab' or its corresponding type declarations.
然而,在我的前面,它返回一个错误,但我可以看到编译"工作"当点击关闭错误对话框时,因为我看到了material-ui时间轴
这个错误是从哪里来的?
package.json
{
"name": "front",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.5.0",
"@emotion/styled": "latest",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "^4.0.0-alpha.61",
...
}
tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
}
试试这个
import * as React from 'react';
import ReactDOM from 'react-dom';
import Button from '@mui/material/Button';
function App() {
return <Button variant="contained">Hello World</Button>;
}
你需要导入这样的内容
import Button from '@mui/material/Button';
我在我的一个老项目中发现了同样的问题,我挠头了一会儿,在这篇文章中找到了解决方案。在{path}
基本上你必须安装包:npm install @material-ui/lab