javascript - 使用新的 React Native 应用程序安装 Flow
问题描述
我正在尝试使用 React Native 应用程序开始使用 Flow,但我总是收到一个错误,即 node_module 没有正确配置 Flow。
Ultimate 在 .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 start
解决方案
有几步...
- 使用流类型的存储库为您的 node_modules 包安装流库定义(“libdefs”)
- 在您的
.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 flow types 像这样浮动,但我发现它比它的价值和any
所有组件都有更多错误,就像这样。缺少类型定义并没有伤害到我。
推荐阅读
- ios - UINavigationBar overlapping status bar when open project in xcode 11
- javascript - waht 是 vscode 显示的 javascript 文档中尖括号的含义
- c# - 优化 C# 代码以计算嵌套循环中的出现次数
- c# - 无法解析类型“BackEnd.Models.UserContext”的服务
- c# - Unity 2019.2.5f1 中的最低 API 级别列表缺失
- python-3.x - pyenv 在 macOS Mojave 上安装 3.8.0b4
- c# - 迭代 Treeview 集合以更新编号方案的最佳方法是什么?
- json - 从前端收到的 Json 在后端变为“null”
- textures - updateAndRelease:GLConsumer 未附加到 OpenGL ES 上下文
- javascript - ReactNative FlatList 不渲染某些项目