skip to Main Content

Follow is my content of index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';


const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

App.js1

import Button from '@mui/material/Button';

function App() {
  return  <Button variant="contained">Button</Button>
}

export default App;

package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.10.6",
    "@emotion/styled": "^11.10.6",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

And you can see in the following picture, nothing is displayed (supposedly to display a button):
enter image description here

How should I solve this?

2

Answers


  1. You have not installed the MUI library, follow the document and install this:

    npm install @mui/material

    Login or Signup to reply.
  2. Please follow the documentation to install Material UI.

    First, try:

    npm install @mui/material @emotion/react @emotion/styled
    

    Then, import @font

    npm install @fontsource/roboto
    

    Add to index.js

    import '@fontsource/roboto/300.css';
    import '@fontsource/roboto/400.css';
    import '@fontsource/roboto/500.css';
    import '@fontsource/roboto/700.css';
    

    And if you want to using icon of Material UI, try:

    npm install @mui/icons-material
    

    Hope that help

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search