"Required module not found" 存在于 node_modules 中的模块

"Required module not found" for module that exists in node_modules

有些模块对 Flow 来说似乎是不可见的。例如,我通过 npm 安装了 react-native-overlay 到我的 node_modules 目录中,但是我从 Flow:

得到了一大堆这样的错误
[js/components/DatePickerOverlay.js:18
 18: let Overlay = require('react-native-overlay');
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ react-native-overlay. Required module not found

这个模块没有类型,所以如果我能让 Flow 完全忽略它就好了。

这是我的 .flowconfig(基于 React Native 的):

https://gist.github.com/almost/20c6caf6d18d0e5c689f

如您所见,我的流程是 0.20.1,并且我有 module.system=haste(根据 React Native 的要求)

我尝试在导入行中添加 //$FlowIgnore 注释,但随后 Flow 抱怨一个不需要的忽略注释!我还尝试创建一个带有虚拟导出的 react-native-flow.js.flow 文件,该文件起初似乎可以工作,但在流程重新启动后停止工作。

关于如何帮助 Flow 找到此模块或使其完全忽略导入行的任何想法?

您似乎忽略了这里:https://gist.github.com/almost/20c6caf6d18d0e5c689f#file-flowconfig-L42-L50

如果您不介意手动输入,请将 react-native-overlay.js 添加到您的界面并输入几个签名。

发生这种情况是因为 flow-typed 中不存在该库。

一个简单的修复可能是在 .flowconfig 文件中创建以下条目:

[ignore]
<PROJECT_ROOT>/libdefs.js
[libs]
./libdefs.js

如果使用 flowtype < 0.60.0 添加 libdefs.js

// @flow

declare module "react-native-overlay" {
    declare var exports: any;
}

或者如果使用 flowtype > 0.60.0

declare module 'react-native-overlay' {
    declare module.exports: any;
}

注意: any是不安全的类型所以你可以随时利用改进库的定义

希望对您有所帮助,