Search code examples
node.jsreactjsantd

Error: Can't resolve 'antd/dist/antd.css'


While importing below mention line in index.js or app.js getting error: Can't resolve 'antd/dist/antd.css' import 'antd/dist/antd.css';

index.js code:

import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter as Router } from "react-router-dom";

import App from './App';
import 'antd/dist/antd.css';

ReactDOM.render(
  <Router>
    <App />
  </Router>,
  document.getElementById("root")
);

package.json :

{
  "name": "App",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@ant-design/icons": "^5.2.5",
    "@reduxjs/toolkit": "^1.9.5",
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "antd": "^5.8.2",
    "axios": "^1.4.0",
    "chart.js": "^4.3.3",
    "html-react-parser": "^4.2.0",
    "millify": "^6.1.0",
    "moment": "^2.29.4",
    "react": "^18.2.0",
    "react-chartjs-2": "^5.2.0",
    "react-dom": "^18.2.0",
    "react-redux": "^8.1.2",
    "react-router-dom": "^6.14.2",
    "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"
    ]
  }
}

FYI, I have used : npx create-react-app.

I have tried using below mention line in app.css but getting error import '~antd/dist/antd.css';


Solution

  • Since you're using antd version 5.x there are some changes. The original antd/dist/antd.css has also been abandoned. If you need to reset some basic styles, please import antd/dist/reset.css.

    For more info please visit this link