יונתן אוזן
יונתן אוזן

Reputation: 57

./src/index.js Module not found: Can't resolve '~antd/dist/antd.css'

I have the issue ./src/index.js Module not found: Can't resolve '~ antd / dist / antd.css', I can not fix it. I tried to put the @import '~ antd / dist / antd.css'; . In css file. Without success.

package.json:

{
  "name": "time-clock",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.5.0",
    "antd": "^4.9.2",
    "firebase": "^8.1.2",
    "polished": "^4.0.5",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.1",
    "styled-components": "^5.2.1",
    "web-vitals": "^0.2.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"
    ]
  }
}

Upvotes: 4

Views: 23313

Answers (3)

In file index.js

import { ConfigProvider, theme } from 'antd';

Wrap the App tag like this:

<ConfigProvider theme={{
          algorithm: theme.darkAlgorithm
}}>
  <App />
</ConfigProvider>

Upvotes: 0

Mohamed Farouk
Mohamed Farouk

Reputation: 1229

Add in App.js

import 'antd/dist/reset.css';

documentation

Upvotes: 2

Jonathan Sanchez
Jonathan Sanchez

Reputation: 9364

@import '~antd/dist/antd.css';

is only meant for css or scss files.


if you started your app with -> npx create-react-app yourAppName

don't import 'antd/dist/antd.css'; into your index.js it will fail !!!


Solution

DO NOT USE THE GET STARTED DOCS

Instead use the Use in create-react-app found here

  1. Add @import '~antd/dist/antd.css'; to the top of App.css file
  2. Then you should be able to use it on any component like import { Button } from 'antd';

enter image description here

Upvotes: 9

Related Questions