我在我的 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 本身。我无法在 codepen 上使用相同的最新稳定版本 "antd": "^3.7.3"
在一个小测试用例上重现该问题。
可能发生了什么?是否发生了某种我需要覆盖的选择性项目范围导入?
最佳答案
您的 node_modules
中似乎有旧版本的 antd
,并且您只更新了 package.json
以包含最新版本,无需重新安装。
您可以删除 node_modules
并重新安装所有内容以获取 package.json
中列出的每个依赖项的所有版本:
rm -rf ./node_modules && npm install
关于reactjs - 无法从 antd react 库导入 Drawer 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51604086/