Unexpected token, expected {

Viewed 227

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/

1 Answers

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

Related