Babel.js “在此类型参数声明后需要箭头函数”错误

yyhrrdl8  于 2022-12-08  发布在  Babel
关注(0)|答案(1)|浏览(149)

运行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 |

以下是配置:
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>;
}

我的配置和React文件有什么问题?

6pp0gazn

6pp0gazn1#

这似乎是React.MixedElement上的排印错误,请将$替换为.

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

相关问题