升级到Flow的最新版本,需要哪些flow-type库?

前端开发 2026-07-08

升级到最新版的Flow之后,Flow似乎连基本的HTML和 DOM都不知道该怎么处理。

我遇到了这个错误:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ flow-typed/environments/dom.js:2455:31

Cannot resolve name DOMRectList. [cannot-resolve-name]

     2452│ // incorrect because there are no ClientRect/ClientRectList globals on the DOM.
     2453│ // Keep these as type aliases for backwards compatibility.
     2454│ declare type ClientRect = DOMRect;
     2455│ declare type ClientRectList = DOMRectList;
     2456│

这是我在 flow-typed.config.json 中的环境列表。我应该怎么判断要添加哪些环境?

  "env": ["node", "html", "dom", "bom", "cssom", "serviceworkers", "jsx"]

解决方案

你在 'dom' 定义上遇到了错误;理论上,在你安装它时,依赖的其他定义也应该自动安装。但根据 flow-typed的成员之一的评论,这似乎并没有正常工作。在这个特定的场景下,你需要添加的环境是 'geometry'(它定义在 DOMRectList 所在的位置)。请查看 这里 的环境列表,并确认你已经把它们全部添加。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章