【发布时间】:2018-07-31 00:54:49
【问题描述】:
我在我的 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" 重现该问题。
可能会发生什么?是否发生了某种需要覆盖的选择性项目范围导入?
【问题讨论】:
-
非常有趣。 It works for me。您是否尝试过删除
node_modules并重新安装所有内容?rm -rf ./node_modules && npm install -
嗯.. 有了这些信息很难说出发生了什么。您确定您使用的是 3.x 版本吗? Drawer 组件在 2.x 版本中不存在。还要检查 node_modules/antd/lib/ 下的文件夹抽屉是否存在。我检查了你的版本,一切正常!
-
package.json > "dependencies" > "antd"显示"^3.7.3"。仔细检查。 -
嘿,你的建议奏效了。我还重新启动了服务器以获得良好的效果。但我很确定我没有更改 node_modules 目录中的任何内容。或者也许我做到了。这怎么可能?非常令人惊讶!
-
可能是您安装了旧版本,在没有实际安装的情况下将
"^3.7.3"添加到package.json,或类似的情况。