我有这个问题。/src/index. js模块没有找到:无法解析“~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"
]
}
}
1条答案
按热度按时间oyjwcjzk1#
@import '~antd/dist/antd.css';
第一个月仅适用于css或scss文件。
如果您使用-〉
npx create-react-app yourAppName
启动应用不要将
import 'antd/dist/antd.css';
安装到您的index.js
中,它将失败!!!溶液
请勿使用
GET STARTED DOCS
而是使用here中的
Use in create-react-app
1.将
@import '~antd/dist/antd.css';
添加到App.css
文件的顶部1.然后,您应该能够在任何组件(如
import { Button } from 'antd';
)上使用它