簡體   English   中英

./src/index.js 找不到模塊:無法解析'~antd/dist/antd.css'

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

我遇到了問題。/src/index.js 找不到模塊:無法解析 '~ antd / dist / antd.css',我無法修復它。 我試着把@import '~ antd / dist / antd.css'; . 在 CSS 文件中。 沒有成功。

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

@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中使用

  1. 添加@import '~antd/dist/antd.css'; App.css文件的頂部
  2. 然后你應該可以在任何組件上使用它,比如import { Button } from 'antd';

在此處輸入圖像描述

在 App.js 中添加

import 'antd/dist/reset.css';

文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM