Home > OS >  "Expected an arrow function after this type parameter declaration" error
"Expected an arrow function after this type parameter declaration" error

Time:03-19

I got this error while running yarn start:

$ yarn start
yarn run v1.22.17
$ run-s build exec
$ babel src/ -d lib/
SyntaxError: .../src/App.js: Expected an arrow function after this type parameter declaration. (8:9)

   6 |
   7 | export default function App(): React$MixedElement {
>  8 |   return <p>Hello, React!</p>;
     |          ^
   9 | }
  10 |

Below are the configs:

package.json

"scripts": {
    "flow": "flow",
    "start": "run-s build exec",
    "exec": "node lib/index.js",
    "build": "babel src/ -d lib/",
},

babel.config.json:

{
  "presets": ["@babel/preset-flow"],
  "plugins": ["babel-plugin-transform-flow-enums"],
  "targets": {
    "esmodules": true
  }
}

App.js:

// @flow

import "./App.css";

import React from "react";

export default function App(): React$MixedElement {
  return <p>Hello, React!</p>;
}

What the issue with my configs and react file?

CodePudding user response:

It seems to be a typo on React.MixedElement, replace the $ by a .:

export default function App(): React.MixedElement {...}

CodePudding user response:

try wrapping the return in brackets

  • Related