1

我从Expo创建了一个 React Native 项目。然后我想给它添加Flow。我注意到在我的node_modules/react-native文件夹中有一个 .flowconfig 所以我将它复制到我的项目的根目录。运行后,flow我从文件中收到了一些警告,node_modules/exponent因此我为整个文件夹添加了一个忽略。之后,我在运行时仍然遇到很多错误flow。这里有几个:

node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:227
227:   /* $FlowFixMe */
       ^^^^^^^^^^^^^^^^ Error suppressing comment. Unused suppression

node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:1120
1120:     if (__DEV__) {
              ^^^^^^^ identifier `__DEV__`. Could not resolve name

node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:2162
2162:     if (__DEV__) {
              ^^^^^^^ identifier `__DEV__`. Could not resolve name
  • 世博SDK版本:14.0.0
  • 流版本:0.37.0
  • 反应原生版本:0.41.2
4

3 回答 3

3

您可以抑制.flowconfig文件中的错误,[options]如下所示:

[options]
suppress_type=$FlowFixMe

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-8]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)

然后,在[libs]部分中,您应该指向所谓的库定义文件,例如:

[libs]
./libdefs.js

libdefs.js中声明:

declare var __DEV__:string;

这些更改应该可以解决您的错误。看:

https://flow.org/en/docs/config/options/#toc-suppress-comment-regex

https://flow.org/en/docs/libdefs/creation/了解详情。

于 2017-04-04T04:50:24.503 回答
0

看起来这可能是对该发布版本的流类型的疏忽。

所有这些错误看起来都相当无害,所以你可以忽略它。如果你绝对不能忽略它,更新到锁定到不同版本 Flow 的更高版本的 React Native 吗?我个人在 React Native @ 0.42 和 Flow @ 0.38 方面取得了不错的成绩(没有错误)。

于 2017-04-04T04:41:33.843 回答
0

发现此问题建议更新 flowconfig 以使用create-react-native-app 的最新版本。似乎对我有用。

于 2018-03-17T19:23:09.033 回答