【发布时间】:2017-04-04 08:12:06
【问题描述】:
我已经为我的 React 项目设置了一个文件夹,用于存放我想直接导入的常用组件。
src/
---components/
---common/
---/TextInput
---/TabSelector
Full folder structure from root
common 中的每个文件夹都有一个 index.jsx(和其他资源,如样式等)和 export default <name> 语句。
所以我的 webpack 配置有以下配置:
resolve: {
modulesDirectories: [
'node_modules',
myCommonComponentsPath
]
}
允许直接导入:import TextInput from 'TextInput'
尝试将此添加到.flowconfig(根据flow's documentiation)不起作用:
[include]
./node_modules/
<PROJECT_ROOT>/src/components/common
这适用于 webpacks 解析器(组件加载和工作),但流程给出以下错误:
9: import TextInput from 'TextInput';
^^^^^^^^^^^ TextInput. Required module not found
任何帮助将不胜感激。 我该如何解决这个问题?
【问题讨论】:
-
从项目根文件夹开始你的文件夹结构是什么?
-
现在更新了链接。
-
谢谢。你试过
import TextInput from 'TextInput/index';吗? -
是的,尝试了所有我能想到的组合。
import TextInput from 'TextInput/index.jsximport TextInput from 'TextInput/index