Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import Drawer component from antd react library

Tags:

reactjs

antd

I am using antd components in my react app. Out of all components, I am facing difficulty in importing and using only the Drawer component. All other components are working fine. My code is rather straightforward.

import React from 'react';
import { Layout, Menu, Button, Drawer } from 'antd';

export class MyDesign extends React.Component {
  ...
  render() {
    return (
      <div>
        <Button />                              <-- works fine
        <Drawer title="Test" visible={true}>    <--- doesn't work
          <p>Some contents...</p>
        </Drawer>
      </div>
    );
  }
}

This causes the following console warning, issued from within webpackHotDevClient

'antd' does not contain an export named 'Drawer'.

which indicates that the issue is with how my app imports antd, and definitely not with antd itself. I was unable to reproduce the issue on a small testcase on codepen, using the same latest stable version of "antd": "^3.7.3".

What might be going on? Is there some sort of selective project-wide import happening that I need to override?

like image 833
S B Avatar asked Aug 23 '26 18:08

S B


1 Answers

It looks like you have an older version of antd in your node_modules, and that you have only updated the package.json to contain the newest version without reinstalling it.

You can remove node_modules and reinstall everything to get all the versions of every dependency listed in package.json:

rm -rf ./node_modules && npm install
like image 105
Tholle Avatar answered Aug 26 '26 08:08

Tholle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!