Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

./src/App.js Module not found: Can't resolve '@material-ui/data-grid' in xxx

I build a react+flask app and I want to use Material-UI I tested the button and it works and I need a data grid, a table and I get this error:

./src/App.js
Module not found: Can't resolve '@material-ui/data-grid' in 'C:\spvreact\react-flask-app\src'

And in the console I get this:

Uncaught Error: Cannot find module '@material-ui/data-grid'
at webpackMissingModule (App.css?4433:45)
at Module../src/App.js (App.css?4433:45)
at __webpack_require__ (bootstrap:784)
at fn (bootstrap:150)
at Module../src/index.js (index.css?f3f6:45)
at __webpack_require__ (bootstrap:784)
at fn (bootstrap:150)
at Object.1 (serviceWorker.js:141)
at __webpack_require__ (bootstrap:784)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1

This is the code:

import React, { useEffect } from 'react';
import logo from './logo.svg';
import './App.css';
import Button from '@material-ui/core/Button';
import { DataGrid } from '@material-ui/data-grid';




function App() {

const columns = [
{ field: 'id', headerName: 'ID', width: 70 },
{ field: 'firstName', headerName: 'First name', width: 130 },
{ field: 'lastName', headerName: 'Last name', width: 130 },
{
  field: 'age',
  headerName: 'Age',
  type: 'number',
  width: 90,
},
{
  field: 'fullName',
  headerName: 'Full name',
  description: 'This column has a value getter and is not sortable.',
  sortable: false,
  width: 160,
  valueGetter: (params) =>
    `${params.getValue('firstName') || ''} ${
      params.getValue('lastName') || ''
    }`,
  },
  ];

const rows = [
{ id: 1, lastName: 'Snow', firstName: 'Jon', age: 35 },
{ id: 2, lastName: 'Lannister', firstName: 'Cersei', age: 42 },
{ id: 3, lastName: 'Lannister', firstName: 'Jaime', age: 45 },
{ id: 4, lastName: 'Stark', firstName: 'Arya', age: 16 },
{ id: 5, lastName: 'Targaryen', firstName: 'Daenerys', age: null },
{ id: 6, lastName: 'Melisandre', firstName: null, age: 150 },
{ id: 7, lastName: 'Clifford', firstName: 'Ferrara', age: 44 },
{ id: 8, lastName: 'Frances', firstName: 'Rossini', age: 36 },
{ id: 9, lastName: 'Roxie', firstName: 'Harvey', age: 65 },
];

useEffect(() => {
fetch('http://127.0.0.1:5000/formular',{
headers : { 
'Content-Type': 'application/json',
'Accept': 'application/json'
}

}).then(response =>
response.json().then(data =>{
console.log(data);
})
);
},[]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
return <div className="App">
  <script src="https://unpkg.com/@material-ui/core@latest/umd/material-ui.development.js" ></script>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css? 
  family=Roboto:300,400,500,700&display=swap" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
  
  

  <div style={{ height: 400, width: '100%' }}>
      <DataGrid rows={rows} columns={columns} pageSize={5} checkboxSelection />
    </div>
  
  </div>;

  }

  export default App;

I tried in cmd npm install @material-ui next or something like that but it still doesn`t import the grid.

Please help

like image 468
SerbanRamon Avatar asked Oct 07 '20 10:10

SerbanRamon


3 Answers

Data-grid does not come included with the core installation of material-ui.

Install data-grid with:

npm install @material-ui/data-grid

Import it with:

import { DataGrid } from '@material-ui/data-grid'
like image 71
Tmfwang Avatar answered Nov 15 '22 08:11

Tmfwang


Data grid does not come with default installation. Refer here

You can install it seperately as:

npm install @material-ui/data-grid

And import it as

import { DataGrid } from '@material-ui/data-grid';
like image 20
neeraj tk Avatar answered Nov 15 '22 08:11

neeraj tk


follow these steps:

  1. install the core material-ui

    npm install @material-ui/core

  2. now intall the data-gird

    npm install @material-ui/data-grid

  3. that show have done the deal!

like image 25
Roohan Avatar answered Nov 15 '22 10:11

Roohan