【问题标题】:Installing Flow with a new React Native App使用新的 React Native 应用程序安装 Flow
【发布时间】:2018-10-16 13:59:11
【问题描述】:

我正在尝试使用 React Native 应用程序开始使用 Flow,但我总是收到一个错误,即 node_module 没有正确配置 Flow。

最终在 .flowconfig 中我添加了一行来忽略 node_module 导演下的所有内容,但这给了我一个错误,它无法找到“react native”

>     Spawned flow server (pid=70665)
>     Logs will go to /private/tmp/flow/zSUserszSaxxxzSWorkspacezSprojectzSAwesomeProject.log
>     Monitor logs will go to /private/tmp/flow/zSUserszSaxxxzSWorkspacezSprojectzSAwesomeProject.monitor_log
>     Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
> App.js:3:40
>     
>     Cannot resolve module react-native.
>     
>          1│ /* @flow */
>          2│ import React from 'react';
>          3│ import { StyleSheet, Text, View } from 'react-native';
>          4│
>          5│ export default class App extends React.Component {
>          6│   render() {
> 
> Error
> ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
> App.js:5:34
> 
> Cannot use property Component [1] with less than 1 type argument.
> 
>      App.js
>       2│ import React from 'react';
>       3│ import { StyleSheet, Text, View } from 'react-native';
>       4│
>       5│ export default class App extends React.Component {
>       6│   render() {

在新的 RN 应用中安装 Flow 的正确方法是什么

create-react-native-app AwesomeProject

cd AwesomeProject
npm 开始

【问题讨论】:

    标签: javascript react-native flowtype


    【解决方案1】:

    有几个步骤...

    1. 使用 flow-typed 存储库为您的 node_modules 包安装 Flow 库定义(“libdefs”)
    2. 在您的 .flowconfig 中,忽略一些更多的 react-native 包。我使用 Expo,所以您可能不需要所有这些:

    类似...

    [ignore]    
          <PROJECT_ROOT>/node_modules/editions
          <PROJECT_ROOT>/node_modules/npm
          <PROJECT_ROOT>/vendor/bundle
    
          ; Ignore various node_modules for react-native
          <PROJECT_ROOT>/frontend/native/node_modules/react-native-gesture-handler/.*
          <PROJECT_ROOT>/frontend/native/node_modules/react-native/.*
          <PROJECT_ROOT>/frontend/native/node_modules/expo/.*
          <PROJECT_ROOT>/frontend/native/node_modules/react-navigation/.*
          <PROJECT_ROOT>/frontend/native/node_modules/xdl/.*
          <PROJECT_ROOT>/frontend/native/node_modules/reqwest/.*
          <PROJECT_ROOT>/frontend/native/node_modules/metro-bundler/.*
          <PROJECT_ROOT>/frontend/native/node_modules/metro/.*
    

    有一些社区定义的 react native 流类型,比如this one,但我发现它比它的价值更多,只有any 所有组件,like this。缺少类型定义并没有伤害到我。

    【讨论】:

      【解决方案2】:

      有问题... 当您将node_modules 标记为被流程忽略时,您会阻止对库的流程改进...我想可以解决node_modules 中的一些错误,并希望库所有者能够修复它=)

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      相关资源
      最近更新 更多