Material UI Typography模块未找到,单独安装后项目编译失败求助
Let's break down what's going wrong and fix this step by step:
Why this error happens
First off, the import path material-ui/Typography is outdated—Material UI uses scoped packages (prefixed with @material-ui/) now. On top of that, the standalone @material-ui/typography package you installed isn't meant to provide the Typography component itself; it's a utility package for customizing typography themes. The actual Typography component lives in the @material-ui/core package.
Step 1: Fix your dependencies
If you only need the Typography component, uninstall the standalone typography package first:
# Using npm npm uninstall @material-ui/typography # Using yarn yarn remove @material-ui/typography
Then install the core Material UI package which includes the Typography component:
# Using npm npm install @material-ui/core # Using yarn yarn add @material-ui/core
Step 2: Correct your import statement
In your src/App.js, update the import line to use the correct scoped path:
// Replace this import Typography from 'material-ui/Typography' // With this import Typography from '@material-ui/core/Typography'
If you actually need the standalone @material-ui/typography package
If you're trying to customize your app's typography theme (not just use the component), keep both packages installed but make sure you import the utilities correctly:
// For theme customization import { createTypography } from '@material-ui/typography' // For the actual component import Typography from '@material-ui/core/Typography'
After making these changes, your project should compile without issues!
内容的提问来源于stack exchange,提问作者Sara

