【问题标题】:Gatsby fail to compile with flowGatsby 编译失败
【发布时间】:2019-08-06 10:14:38
【问题描述】:

我通过添加插件 gatsby-plugin-flow 在我的 Gatsby 项目中安装了 Flow。

它在项目根目录中创建了一个 .flowconfig 文件,并在 package.json 中创建了一个 "gatsby-plugin-flow": "^1.0.4" 依赖项。

当我运行 gatsby develop 时,出现错误:

ERROR in ./src/components/layout.js
Module build failed (from ./node_modules/gatsby/dist/utils/babel-loader.js):
SyntaxError: /Users/iqc/project/src/components/layout.js: Unexpected token, expected "," (10:29)

   8 | import "./layout.css"
   9 | 
> 10 | const Layout = ({ children } : Object) => (
     |                              ^
  11 |   <StaticQuery
  12 |     query={graphql`

Babel 似乎无法编译项目。 也许盖茨比中的 ES6 有问题?

我也尝试使用官方文档(无插件)安装 Flow,但出现同样的问题。

谢谢!

【问题讨论】:

    标签: reactjs babeljs flowtype gatsby


    【解决方案1】:

    您已经安装了gatsby-plugin-flow,但您还需要将其作为插件添加到gatsby-config.js 文件中。

    gatsby-config.js

    module.exports = {
      plugins: ['gatsby-plugin-flow'],
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-07
      • 2021-06-14
      • 2021-01-29
      • 2018-11-06
      • 1970-01-01
      • 2013-02-01
      • 2016-08-16
      • 2015-09-07
      • 2013-07-03
      相关资源
      最近更新 更多