Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempted import error: 'Icon' is not exported from 'antd'

I have created a react app using 'create-react-app' and in one of my project files, i'm using the following import statement;

import { Icon } from 'antd',

and receiving the following error:

Attempted import error: 'Icon' is not exported from 'antd'.

not sure what the issue is. please help.

like image 207
Mushood Hanif Avatar asked Mar 14 '20 22:03

Mushood Hanif


2 Answers

On upgrading the version of Ant Design to v4, one of the major breaking changes have been that Icon is no longer exported from antd package.

Also instead of having string based icon references like:

// Before
<Icon type="smile" />

In v4:

import { SmileOutlined } from '@ant-design/icons';

<SmileOutlined />

There is still an Icon export, but that is from the package @ant-design/icons instead of just antd. This Icon export can be used for adding custom icons.

Docs Changelog

like image 76
Agney Avatar answered Sep 17 '22 19:09

Agney


In v4, the icons are a default export, so do

import Icon from '@ant-design/icons';

instead of

import {Icon} from 'antd';

You might also need to do npm install @ant-design/icons --save-dev

like image 23
Jkarttunen Avatar answered Sep 18 '22 19:09

Jkarttunen