【问题标题】:react native and flow error messages对本机和流错误消息做出反应
【发布时间】:2017-08-07 07:59:27
【问题描述】:

您好,我想用 React Native 打个招呼。 我创建了项目 'react-native init' 更改了 '.flowconfig' 中的流程版本。

运行流程,它给了我 153 个错误,这些错误位于 node_modules 文件夹中,例如 node_modules/react-native/Libraries

有人遇到同样的问题吗?

【问题讨论】:

    标签: react-native flowtype


    【解决方案1】:

    发现这个issue 建议更新flowconfig 以使用latest version from create-react-native-app。似乎对我有用。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。你需要做两步:

      1。将您的 .flowconfig 与此文件进行比较并添加您缺少的行:

      [ignore]
      ; We fork some components by platform
      .*/*[.]android.js
      
      ; Ignore "BUCK" generated dirs
      <PROJECT_ROOT>/\.buckd/
      
      ; Ignore unexpected extra "@providesModule"
      .*/node_modules/.*/node_modules/fbjs/.*
      
      ; Ignore duplicate module providers
      ; For RN Apps installed via npm, "Libraries" folder is inside
      ; "node_modules/react-native" but in the source repo it is in the root
      .*/Libraries/react-native/React.js
      .*/Libraries/react-native/ReactNative.js
      
      <PROJECT_ROOT>/node_modules/.*
      <PROJECT_ROOT>/libdefs.js
      .*/__tests__/.*
      
      [include]
      
      [libs]
      node_modules/react-native/Libraries/react-native/react-native-interface.js
      node_modules/react-native/flow
      ./libdefs.js
      

      2。在根文件夹中创建 libdefs.js。它应该看起来像这样:

      declare module 'react-native' { declare var exports: any; }
      declare module 'jest' { declare var exports: any; }
      

      另外,声明所有模块流抛出错误(例如'mobx' - 我知道这可能有点令人沮丧,但必须这样做)

      【讨论】:

      • 谢谢,它消除了大部分错误,但下面有一个。 This modules resolves to "&lt;&lt;PROJECT_ROOT&gt;&gt;/../../node_modules/react/package.json", which is outside both your root directory and all of the entries in the [include] section of your .flowconfig. You should either add this directory to the [include] section of your .flowconfig, move your .flowconfig file higher in the project directory tree, or move this package under your Flow root directory.: /Users/*********/ReactNative/ToDoList/index.ios.js:18 我真的不知道要为此添加哪个模块。
      • 这里的第 2 步不会中断对从 react-native 导入的任何内容的类型检查吗?你可以写 &lt;Text nonExistantProp="purple-panda"&gt;&lt;/Text&gt; 和 flow 会很有趣。
      • 如果我错了,请纠正我,但这种方法让我印象深刻:“排除所有内容并列入白名单”va。 “包括所有内容和黑名单”。我觉得它有可能危及 node_modules 的流类型的价值。我这样说,但没有明显更好的解决方案。如果我能弄清楚会更新。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 2020-07-29
      • 2020-12-14
      相关资源
      最近更新 更多