无法从 antd react 库导入 Drawer 组件

Cannot import Drawer component from antd react library

我在我的 React 应用中使用了 antd 组件。在所有组件中,我在导入和使用 Drawer 组件时遇到困难。所有其他组件都工作正常。我的代码相当简单。

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>
    );
  }
}

这会导致以下控制台警告,从 webpackHotDevClient

中发出
'antd' does not contain an export named 'Drawer'.

这表明问题出在我的应用程序如何导入 antd,而不是 antd 本身。我无法使用相同的最新稳定版本 "antd": "^3.7.3" 在 codepen 上的一个小测试用例上重现该问题。

可能发生了什么?是否发生了某种我需要覆盖的选择性项目范围导入?

您的 node_modules 中似乎有旧版本的 antd,您只是更新了 package.json 以包含最新版本,而没有重新安装它。

您可以删除 node_modules 并重新安装所有内容以获得 package.json 中列出的每个依赖项的所有版本:

rm -rf ./node_modules && npm install