【发布时间】:2020-02-01 05:48:06
【问题描述】:
我有一个 Visual Studio 2019 (v16.3.2) React TypeScript 项目,其中包含 Material-UI 组件。 TypeScript 编译器无法解析任何 @material-ui 导入,并出现如下错误,导致无法生成相应的 JavaScript。
Error TS2307 (TS) Cannot find module '@material-ui/core/Grid'.
上述错误的模块是
import * as React from 'react';
// Material-UI
import Grid from '@material-ui/core/Grid';
// Components
import SkiWeekends from './SkiWeekends';
const EZForm: React.FC = () => {
return (
<React.Fragment>
<Grid container spacing={3}>
<Grid item xs={12}>
<SkiWeekends/>
</Grid>
<Grid item xs={12}>
A
</Grid>
<Grid item xs={12}>
B
</Grid>
<Grid item xs={12}>
A
</Grid>
</Grid>
</React.Fragment>
);
}
export default EZForm;
tsconfig.json 是
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
package.json 是
{
"name": "msc",
"version": "3.0.0",
"private": true,
"dependencies": {
"@types/jest": "24.0.18",
"@types/node": "12.7.9",
"@types/react": "16.9.4",
"@types/react-dom": "16.8.2",
"@types/react-redux": "7.1.4",
"@types/react-router-dom": "5.1.0",
"@types/redux-thunk": "2.1.32",
"@material-ui/core": "4.5.0",
"@material-ui/icons": "4.4.3",
"@material-ui/styles": "4.5.0",
"react": "16.10.1",
"react-dom": "16.10.1",
"react-redux": "7.1.1",
"react-router-dom": "5.1.2",
"react-scripts": "3.1.2",
"redux": "4.0.4",
"redux-devtools-extension": "2.13.8",
"redux-thunk": "2.3.0",
"typescript": "3.6.3"
},
"scripts": {
"start": "rimraf ./build && react-scripts start",
"build": "react-scripts build",
"test": "cross-env CI=true react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"lint": "eslint ./src/"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
我已验证 @material-ui 包已安装在 node_modules 文件夹中。
所有其他包/导入工作正常。对为什么在 TS 编译期间没有解决 material-ui 模块的想法表示赞赏。
【问题讨论】:
标签: reactjs typescript material-ui visual-studio-2019