首页 > 解决方案 > Cant import Table Container in ReactJS - Material UI

问题描述

I am trying to create a table component but cant import TableContainer Component from material-ui:

Attempted import error: 'TableContainer' is not exported from '@material-ui/core'.

I require it at the top of the page like this:

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { TableRow, TableHead, TableContainer, TableCell, TableBody, Table, Paper } from '@material-ui/core';

And here is my package.json and i tried npm install && npm update too.

{
  "name": "link_validator",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.8.0",
    "@material-ui/icons": "^4.5.1",
    "@material-ui/styles": "^4.7.1",
    "@material/button": "^4.0.0",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-redux": "^7.1.3",
    "react-scripts": "^3.3.0",
    "redux": "^4.0.4",
    "styled-components": "^4.4.1",
    "typescript": "^3.7.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "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"
    ]
  }
}

标签: reactjsmaterial-ui

解决方案


正如@AtinSingh 建议的那样,我尝试npm卸载并再次安装,将最新的写入package.json +导入而不进行解构,它起作用了。


推荐阅读