首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gatsby构建失败google-字体

Gatsby构建失败google-字体
EN

Stack Overflow用户
提问于 2021-03-16 15:19:22
回答 1查看 1.2K关注 0票数 4

我好像遇到了以下错误,

代码语言:javascript
复制
>$ 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看起来像这样,

代码语言:javascript
复制
{
      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`],
          },
        ],
      },
    },

package.json

代码语言:javascript
复制
"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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-16 16:44:00

根据一些GitHub线程(https://github.com/gatsbyjs/gatsby/issues/27607),它似乎是一个未解决的错误(影响比^2.25.1更大的版本),他们建议使用其他包,例如:

在进行了适当的配置之后,这个问题就应该解决了。

请记住,如果您使用的是Gatsvy v3,那么在升级到Gatsby的新版本之前,可能会不推荐某些包。

我个人使用gatsby-plugin-google-fonts-v2并且工作非常完美。您可以按照生成的<link>中的字体堆栈来检查从谷歌加载的字体,在本例中:

代码语言:javascript
复制
{
  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`,
      }
    ]
  }
},
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66658149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档