簡體   English   中英

gatsby-plugin-react-svg 導致太多遞歸錯誤

[英]gatsby-plugin-react-svg causing too much recursion error

我已經安裝了gatsby-plugin-react-svg ,但是當我更新gatsby-config文件時,它會導致“遞歸過多”錯誤。 我已經嘗試了 gatsby 文檔頁面上推薦的配置,但它仍然給我錯誤。

錯誤:

InternalError: too much recursion
./node_modules/style-loader/lib/urls.js/module.exports
node_modules/style-loader/lib/urls.js:57

  54 | 
  55 |  /gi  = Get all matches, not the first.  Be case insensitive.
  56 |  */
> 57 | var fixedCss = css.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi, function(fullMatch, origUrl) {
     | ^  58 |  // strip quotes (if they exist)
  59 |  var unquotedOrigUrl = origUrl
  60 |      .trim()

gatsby-config.js

    plugins: [
        `gatsby-plugin-react-helmet`,
        {
            resolve: `gatsby-source-filesystem`,
            options: {
                name: `images`,
                path: `${__dirname}/src/assets/images`,
            },
        },
        `gatsby-plugin-react-svg`,
        `gatsby-transformer-sharp`,
        `gatsby-plugin-sass`,
        `gatsby-plugin-sharp`,
        {
            resolve: `gatsby-plugin-manifest`,
            options: {
                name: `gatsby-starter-default`,
                short_name: `starter`,
                start_url: `/`,
                background_color: `#663399`,
                theme_color: `#663399`,
                display: `minimal-ui`,
                icon: `src/assets/images/favicon.png`, // This path is relative to the root of the site.
            },
        },

您需要通過指定 SVG 文件夾來配置插件。 gatsby-config.js添加以下配置:

plugins: [
    `gatsby-plugin-react-helmet`,
    {
        resolve: `gatsby-source-filesystem`,
        options: {
            name: `images`,
            path: `${__dirname}/src/assets/images`,
        },
    },
    {
       resolve: "gatsby-plugin-react-svg",
       options: {
           rule: {
              include: /svg/ 
          }
      }
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sass`,
    `gatsby-plugin-sharp`,
    {
        resolve: `gatsby-plugin-manifest`,
        options: {
            name: `gatsby-starter-default`,
            short_name: `starter`,
            start_url: `/`,
            background_color: `#663399`,
            theme_color: `#663399`,
            display: `minimal-ui`,
            icon: `src/assets/images/favicon.png`, // This path is relative to the root of the site.
        },
    },

請記住, include規則是一個與文件夾名稱完全匹配的正則表達式。 如果您有類似images/svg的結構,則必須將規則中的路徑名設置為/svg/

資產文件夾必須只包含 SVG 資產,否則可能會導致遞歸問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM