防止FlowType检查node_modules中的错误 [英] prevent FlowType to check error in node_modules

查看:105
本文介绍了防止FlowType检查node_modules中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索解决方案或解决该问题,但没有成功. 以下是描述流程安装以及最终面临的问题的一些步骤.

I have tried searching for the solution or work around to solve this but no success. Here are some steps to describe my flow installation and eventually the issue I am facing.

第1步:我使用以下命令创建了一个新的react native项目 react-native init TestProject.

Step 1: I have created a new react native project using react-native init TestProject.

我想为我的项目配置,但是没有 .flowconfig 文件. 我们知道,需要使用以下脚本指定流版本以便在本地为项目安装流: yarn add --dev flow-bin@0.79.1 babel-preset-flow.

I wanted to configure flow for my project, but there was no .flowconfig file. As we know that the flow version is needed to be specified for installing flow locally for the project, using the following script: yarn add --dev flow-bin@0.79.1 babel-preset-flow.

步骤2:即使我没有.flowconfig文件,因此也没有安装哪个特定版本的信息,我还是尝试使用以下方法为我的项目安装流程:

Step 2: Even though I do not have .flowconfig file and hence no information of which specific version of flow to install, I try to install flow for my project using this:

yarn add --dev flow-bin babel-preset-flow.这已安装了最新的流程 0.79.1 .

yarn add --dev flow-bin babel-preset-flow.This has installed the latest flow 0.79.1.

步骤3:要生成.flowconfig文件,请使用以下脚本: ./node_modules/.bin/flow init.这会在项目目录中创建 .flowconfig 文件,并带有一些默认条目,如下所示:

Step 3: To generate .flowconfig file, following script is used: ./node_modules/.bin/flow init. This created the .flowconfig file in project directory with some default entries as follows:

步骤4:我重新启动了VSCode以启动流服务器:

Step 4: I restarted the VSCode to start flow server:

当流服务器正在运行时,在这里我发现react-native库存在98个问题:

As the flow server was running, here I found out the there are 98 problems with the react-native library:

第5步::我在 [忽略] 下添加了./node_modules/. . flowconfig 文件,然后再次重新启动VSCode.

Step 5 : I added ./node_modules/. under [ignore] in .flowconfig file and restarted VSCode again.

第6步:现在,流捕获的错误是,它找不到模块react-native:

Step 6 : Now the error caught by flow is, it cannot find the module react-native:

这是项目的package.json: 这是React Native环境信息:

Here is the project's package.json: Here is the React Native Environment Info:

请建议是否有人解决了此问题. 预先感谢.

Please suggest if anyone has solved this issue. Thanks in advance.

推荐答案

您可以使用.flowconfig中的[untyped] *部分来告诉Flow将文件视为无类型文件,但仍可以识别它们存在甚至更好地使用 [declarations]选项即使在出现错误时也仅使用类型库本身.这样可以防止导入问题.在您的情况下,您可能只想忽略非常具体的依赖关系,因为从节点模块内部的库中获取类型通常很有用.

You can use the [untyped]* section in your .flowconfig to tell Flow to treat the files as untyped but still recognise that they exist or even better use the new [declarations] option to just use the types even when there are errors in the library itself. This will prevent the import problem. In your case you might want to ignore only very specific dependencies because it is generally useful to get the types from libraries that are inside of your node modules.

*在 Flow v0.61.0 中引入

* Introduced in Flow v0.61.0

这篇关于防止FlowType检查node_modules中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆