意外的令牌,预期{

发布于 2025-02-01 00:04:20 字数 613 浏览 1 评论 0 原文

在我的.flowConfig中,我在选项下添加了 enums = true

[options]
enums=true

但是我遇到了此错误,并且使用createActapp创建的应用不想编译此枚举。

Unexpected token, expected "{" (2:7)

  1 | // @flow
> 2 | export enum Variant {
    |        ^
  3 |   Primary = 'primary',
  4 |   Secondary = 'secondary',
  5 |   Success = 'success',

我一直在谷歌搜索时没有运气,也许有人在这里解决了这个问题?

更新: 使用Create React App(2.0)创建新的应用程序后,我会遇到相同的错误,其中Flow声称:“ Create Apple App已经支持Flow。”可以在他们的页面上看到:

In my .flowconfig i've added enums=true under options :

[options]
enums=true

however i'm getting this error, and app created with createreactapp doesnt wanna compile this enum.

Unexpected token, expected "{" (2:7)

  1 | // @flow
> 2 | export enum Variant {
    |        ^
  3 |   Primary = 'primary',
  4 |   Secondary = 'secondary',
  5 |   Success = 'success',

I've been googling without luck, maybe someone here solved this problem ?

update:
I'm getting the same error after creating a fresh app using Create React App (2.0) for which Flow claims that : "Create React App already supports Flow by default." as it can be seen on their page :
https://flow.org/en/docs/tools/create-react-app/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖兔^ω^ 2025-02-08 00:04:20

您是否完成了以下链接中提到的这些和其他提到的先决条件? (看来您当前的设置尚不支持枚举语法


  • 新的语法
  • 将babel-plugin-transform-flow-eNums添加到您的babel变换
    管道
  • 将流动式 - 暴期限模块添加到您的生产依赖性
    (从转换的输出中调用)
  • 在.flowconfig中启用eNums = true [options]
    有关详细信息的部分

,请参阅本文:

href =“ https://medium.com/flow-type/introducing-flow-enums-16d4239b3180” rel =“ nofollow noreferrer”

< a href =“ https://flow.org/en/docs/enums/enabling-enums/” rel =“ nofollow noreferrer”>在项目中启用枚举

Have you done prerequisites including these and others that are mentioned in the following links? (It seems your current setting does not support enum syntax yet)

  • Upgrade your tooling (e.g. Prettier, Babel, Flow, etc.) to support
    the new syntax
  • Add babel-plugin-transform-flow-enums to your Babel transform
    pipeline
  • Add the flow-enums-runtime module to your production dependencies
    (called from the output of the transform)
  • Enable in your .flowconfig by adding enums=true in the [options]
    section

For details refer to this this post:

Introducing Flow Enums

Enabling enums in your project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文