Gatsby.js-Typography.js

时间:2018-07-16 07:14:31

标签: typography gatsby

自安装typography.js以来,出现此错误:

error There was an error compiling the html.js component for the development server.

  14 |   // Create family + styles string
  15 |   var fontsStr = '';
> 16 |   if (props.typography.options.googleFonts) {
     | ^
  17 |     var fonts = props.typography.options.googleFonts.map(function (font) {
  18 |       var str = '';
  19 |       str += font.name.split(' ').join('+');

  WebpackError: Cannot read property 'googleFonts' of undefined

  - GoogleFont.js:16 GoogleFont
    ~/react-typography/dist/GoogleFont.js:16:1
...

我不确定这意味着什么或如何解决。 我正在使用Gatsby.js默认入门包

typography.js如此:

import Typography from "typography";

const typography = new Typography({
  baseFontSize: "18px",
  baseLineHeight: 1.45,
  headerFontFamily: [
    "Avenir Next",
    "Helvetica Neue",
    "Segoe UI",
    "Helvetica",
    "Arial",
    "sans-serif",
  ],
  bodyFontFamily: ["Georgia", "serif"],
});

和gatsby-config.js:

module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-styled-components`,
    {
      resolve: `gatsby-plugin-typography`, 
      options: {
        pathToConfigModule: 'src/utilities/typography.js'
      },
    },
  ]
};

1 个答案:

答案 0 :(得分:1)

我只是遇到了相同的错误,因此可以通过在底部添加导出来修复它,如下所示:

int getIndex(int a, int b){
      std::string a_str = std::to_string(a);
      std::string b_str = std::to_string(b);
      return a_str.find(b_str);
}

感谢reactiflux不和谐的八度法则为我提供了帮助。现在效果很好。希望有帮助!