简体   繁体   English

gatsby-plugin-react-svg 导致太多递归错误

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

I've installed gatsby-plugin-react-svg , but when I update gatsby-config file, it causes a 'too much recursion' error.我已经安装了gatsby-plugin-react-svg ,但是当我更新gatsby-config文件时,它会导致“递归过多”错误。 I've tried the configuration recommended on the gatsby documentation pages but it still gives me the error.我已经尝试了 gatsby 文档页面上推荐的配置,但它仍然给我错误。

error:错误:

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 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.
            },
        },

You need to configure the plugin by specifying the SVG folder.您需要通过指定 SVG 文件夹来配置插件。 In your gatsby-config.js add the following configuration: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.
        },
    },

Keep in mind that the include rule is a regular expression that matches exactly the folder name.请记住, include规则是一个与文件夹名称完全匹配的正则表达式。 If you have a structure like images/svg , the pathname in the rule must be set to /svg/ either way.如果您有类似images/svg的结构,则必须将规则中的路径名设置为/svg/

The asset folder must only contain SVG assets, if not, it may cause recursion issues.资产文件夹必须只包含 SVG 资产,否则可能会导致递归问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM