当前位置:网站首页>import error: ‘Icon‘ is not exported from ‘antd‘. Import icon error
import error: ‘Icon‘ is not exported from ‘antd‘. Import icon error
2022-07-26 08:21:00 【Timeline principle】
Issues an error :
Attempted import error: 'Icon' is not exported from 'antd'.
Question why :
Ant Design from v3 Upgrade to v4 Lead to
Icon upgrade ( Click to view the document )
stay [email protected] in , We introduced svg Icon ( Why use svg Icon ?). Using a string named icon API Can't load on demand , Therefore, the total introduction of svg Icon file , This greatly increases the size of the packed product . stay 4.0 in , We adjusted the use of icons API To support tree shaking, Reduce antd The default package size is about 150 KB ( Gzipped ).
Old edition Icon The way of use will be abandoned :
import {
Icon, Button } from 'antd';
const Demo = () => (
<div>
<Icon type="smile" />
<Button icon="smile" />
</div>
);
4.0 On demand introduction will be adopted in :
import {
Button } from 'antd';
// tree-shaking supported
- import {
Icon } from 'antd';
+ import {
SmileOutlined } from '@ant-design/icons';
const Demo = () => (
<div>
- <Icon type="smile" />
+ <SmileOutlined />
<Button icon={
<SmileOutlined />} />
</div>
);
// or directly import
import SmileOutlined from '@ant-design/icons/SmileOutlined';
You will still be able to use it through compatible packages :
import {
Button } from 'antd';
import {
Icon } from '@ant-design/compatible';
const Demo = () => (
<div>
<Icon type="smile" />
<Button icon="smile" />
</div>
);
Solution :
We can solve it through the solution described in the document , However, the following errors will still be reported after the execution :
Module not found: Can't resolve '@ant-design/compatible'
We can solve it with the following order :
npm add @ant-design/compatible
边栏推荐
猜你喜欢
随机推荐
BGP routing principle
I am 35 years old.
Basic music theory rhythm connection problem, very important
数组的介绍--Array
2022-07-09 group 5 Gu Xiangquan's learning notes day02
Special lecture 2 dynamic planning learning experience (should be updated for a long time)
2W word detailed data Lake: concept, characteristics, architecture and cases
An empirical study on urban unemployment in Guangxi (Macroeconomics)
CentOS install mysql5.7
万字长文 | 深入理解 OpenFeign 的架构原理
Introduction to arrays -- array
有点牛逼,一个月13万+
Awk operation
2022-7-9 personal qualifying 6 competition experience
Common Oracle functions
BGP --- 边界网关协议
This is a picture
[June 29, 2022] examination summary
Daily Note (11) -- word formula input arbitrary matrix
吉他五线谱联系 茉莉花









