【问题标题】:Flow seems not to respect include option?流似乎不尊重包含选项?
【发布时间】: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

标签: reactjs flowtype


【解决方案1】:

您需要使用module.system.node.resolve_dirname 设置,这与include 设置不同。由于您要告诉 Webpack 一个新的位置来查找模块,因此您还需要告诉 Flow 那个新位置。

[options]
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=src/components/common

路径与“.flowconfig”文件的位置相关。

【讨论】:

  • 嗯,听起来很有道理,谢谢!我会看看下周是否有时间来验证它。 :)
猜你喜欢
  • 1970-01-01
  • 2019-07-12
  • 1970-01-01
  • 2014-10-06
  • 2017-07-04
  • 2019-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多