【问题标题】:./src/index.js Module not found: Can't resolve '~antd/dist/antd.css'./src/index.js 模块未找到:无法解析 '~antd/dist/antd.css'
【发布时间】:2021-03-19 18:58:38
【问题描述】:

我有问题 ./src/index.js Module not found: Can't resolve '~antd / dist / antd.css',我无法修复。 我试着把@import '~antd/dist/antd.css'; .在 css 文件中。 没有成功。

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"
    ]
  }
}

【问题讨论】:

    标签: reactjs


    【解决方案1】:

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

    仅适用于 css 或 scss 文件。


    如果您使用 -> npx create-react-app yourAppName 启动应用程序

    不要将import 'antd/dist/antd.css'; 插入到您的index.js 中,它会失败!!!


    解决方案

    不要使用GET STARTED DOCS

    改为使用找到的Use in create-react-app here

    1. @import '~antd/dist/antd.css'; 添加到App.css 文件的顶部
    2. 那么你应该可以在任何组件上使用它,比如import { Button } from 'antd';

    【讨论】:

      猜你喜欢
      • 2018-11-19
      • 2022-12-06
      • 2021-06-20
      • 2017-12-28
      • 2022-01-26
      • 2019-11-22
      • 2020-09-21
      • 2019-08-05
      • 1970-01-01
      相关资源
      最近更新 更多