简体   繁体   中英

why ant design doesn't load CSS in reactjs

I making a frontend with a react and ant-design but I have problem there is no error but page look like html without CSS and I use layout component

that is what I use: https://ant.design/components/layout/ (Header-Content-Footer)

npm version: 6.14.9 nodejs version: 14.15.3

here some code:

src/index.js:

import React from "react";
import ReactDom from "react-dom";

import App from "./app";

class CustomMain extends React.Component {
  render() {
    return <App />;
  }
}

ReactDom.render(<CustomMain />, document.getElementById("root"));

src/app.js:

import React from "react";
import CustomLayout from "./containers/Layout";

class App extends React.Component {
  render() {
    return <CustomLayout />;
  }
}

export default App;

src/containers/Layout.js:

import React from "react";
import CustomLayout from "./containers/Layout";

class App extends React.Component {
  render() {
    return <CustomLayout />;
  }
}

export default App;

package.json:

{
  "name": "gui",
  "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.6.0",
    "antd": "^4.9.4",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.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"
    ]
  }
}

Sounds like you're missing an import.
Make sure you added import 'antd/dist/antd.css'; in the index.js file.

You can look for more info here: https://ant.design/docs/react/getting-started

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM