css - Gatsby 构建失败 google-fonts

标签 css gatsby google-fonts

我似乎遇到了以下错误,

>$ gatsby build                                          
success open and validate gatsby-configs - 0.065s
success load plugins - 1.222s
success onPreInit - 0.019s
success delete html and css files from previous builds - 0.002s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's no stale data.
success initialize cache - 0.029s
success copy gatsby files - 0.039s

 ERROR #11321  PLUGIN

"gatsby-plugin-prefetch-google-fonts" threw an error while running the onPreBootstrap lifecycle:

ENOENT: no such file or directory, stat '.cache/google-fonts//fonts'



Error: ENOENT: no such file or directory, stat '.cache/google-fonts//fonts'

not finished onPreBootstrap - 7.272s
我的 gatsby-config.js 看起来像这样,
{
      resolve: `gatsby-plugin-prefetch-google-fonts`,
      options: {
        fonts: [
          {
            family: `Poppins`,
            variants: [`300`, `400`, `500`, `600`, `700`],
          },
          {
            family: `Fira Sans`,
            variants: [`100`, `300`, `400`, `500`, `600`, `700`],
          },
        ],
      },
    },
包.json
"dependencies": {
    "@styled-system/theme-get": "^5.1.2",
    "axios": "^0.21.1",
    "babel-plugin-styled-components": "^1.12.0",
    "disqus-react": "^1.0.10",
    "formik": "^2.1.5",
    "gatsby": "^2.24.57",
    "gatsby-image": "^2.4.17",
    "gatsby-plugin-feed": "^2.5.11",
    "gatsby-plugin-google-analytics": "^2.3.13",
    "gatsby-plugin-lodash": "^3.3.10",
    "gatsby-plugin-mailchimp": "^5.2.2",
    "gatsby-plugin-manifest": "^2.4.28",
    "gatsby-plugin-offline": "^3.2.27",
    "gatsby-plugin-prefetch-google-fonts": "^1.4.3",
},
我尝试了以下但似乎不起作用 - Gatsby - Adding Google fonts to Gatsby site

最佳答案

根据一些 GitHub 线程( https://github.com/gatsbyjs/gatsby/issues/27607 ),这似乎是一个 Unresolved 错误(影响大于 ^2.25.1 的版本),他们建议使用替代软件包,例如:

  • gatsby-plugin-google-fonts
  • gatsby-plugin-preload-fonts

  • 正确配置后,问题应该消失了。
    请记住,如果您使用 Gatsvy v3 ,在升级到 Gatsby 的新版本之前,某些软件包可能会被弃用。
    我个人使用 gatsby-plugin-google-fonts-v2 并且完美运行。您可以跟踪生成的<link>中的字体堆栈检查从谷歌加载的字体,在这种情况下:
    {
      resolve: `gatsby-plugin-google-fonts-v2`,
      options: {
        fonts: [
          {
            family: `Poppins:wght@300;400;500;600;700`,
          },
          {
            family: `Fira Sans:wght@100;300;400;500;600;700`,
          }
        ]
      }
    },
    

    关于css - Gatsby 构建失败 google-fonts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66658149/

    相关文章:

    html - 是否可以在标题容器全屏宽度内制作一个 div?

    shopify - Gatsby 如何在前端隐藏 API key

    javascript - 如何在没有链接组件的情况下更改 gatsby 中的路线?

    python - 如何在单个虚拟主机上服务 django 和 gatsby?

    html - 将 <li> 中的文本基线向上移动 2 px

    jquery - 单击时 Fancybox 关闭按钮消失

    css - 特殊字符在 Firefox 中渲染不当

    javascript - 如何将谷歌字体添加到 React Native?

    wordpress - 谷歌字体未加载到 wordpress 主题中

    css - Sass 有不同的运算符 (!=) 吗?