简体   繁体   English

Gatsby - 模块解析失败:意外字符“�”

[英]Gatsby - Module parse failed: Unexpected character '�'

Hi I've been trying to run Gatsby for a week now.嗨,我已经尝试运行 Gatsby 一个星期了。

I'm trying to transfer my old Gatsby site to the latest hello-world since my Mac upgrade has forced me to move on.我正在尝试将我的旧 Gatsby 网站转移到最新的 hello-world,因为我的 Mac 升级迫使我继续前进。

I've gotten all plugins upgraded and installed but when I try to run I get this: 'Module parse failed: Unexpected character '�''我已经升级并安装了所有插件,但是当我尝试运行时,我得到了这个:'模块解析失败:意外字符'�''

Is there a way to either get more info on what is unexpected?有没有办法获得更多关于意外情况的信息? Or any ideas on how to solve this?或者关于如何解决这个问题的任何想法?

Pastebin of gatsby-config: https://pastebin.com/FzJqgdx0 gatsby-config 的 Pastebin: https ://pastebin.com/FzJqgdx0

plugins: [
    `gatsby-plugin-styled-components`,
    `gatsby-plugin-image`,
    `gatsby-plugin-sharp`,
    `gatsby-transformer-sharp`, // Needed for dynamic images
    `gatsby-plugin-use-query-params`,
    `gatsby-transformer-json`,
    {
      resolve: `gatsby-plugin-sass`,
      options: {
        implementation: require("node-sass"),
      },
    },
    {
      resolve: `gatsby-plugin-alias-imports`,
      options: {
        alias: {
          "@components": "src/components",
          "@images": "src/assets/images",
          "@assets": "src/assets",
          "@utils": "src/utils",
        },
        extensions: [".js", ".jsx", ".ts", ".tsx"],
      },
    },
    {
      resolve: `gatsby-plugin-breadcrumb`,
      options: {
        defaultCrumb: {
          key: "Home",
          location: {
            pathname: "/",
          },
          crumbLabel: "Home",
          crumbSeparator: " / ",
        },
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/assets/images/`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `data`,
        path: `./data/`,
      },
    },
    {
      resolve: "gatsby-plugin-react-svg",
      options: {
        rule: {
          include: "/assets/images",
        },
      },
    },
  ],

I'm using svg, scss, and pdfs in my project which worked in the past.我在过去工作的项目中使用 svg、scss 和 pdfs。

The error can come from multiple reasons, I think it lacks a little debugging from what you've tried, the changes you made, etc, to provide a more solid answer.该错误可能来自多种原因,我认为它缺少您尝试过的内容、所做的更改等的一些调试,以提供更可靠的答案。

However, in your gatsby-config I think there's an odd configuration regarding the gatsby-plugin-react-svg .但是,在您的gatsby-config中,我认为关于gatsby-plugin-react-svg有一个奇怪的配置。 As you can see in Import SVG as a component in Gatsby the include rule is a regular expression, hence must match the pattern, and it should match a folder in your /src folder, it's not a path itself (so remove the quotes).正如您在将 SVG 作为 Gatsby 中的组件导入中看到的那样, include规则是一个正则表达式,因此必须匹配模式,并且它应该匹配/src文件夹中的文件夹,它本身不是路径(所以删除引号)。 Try the following:尝试以下操作:

{
  resolve: "gatsby-plugin-react-svg",
  options: {
    rule: {
      include: /images/,
    },
  },

Be also aware that the folder you include, must only contain SVG assets , otherwise it will break the compilation.另请注意,您包含的文件夹只能包含 SVG assets ,否则会破坏编译。 If the /images folder doesn't match this condition, create a new separate folder for your SVG assets.如果/images文件夹不符合此条件,请为您的 SVG 资产创建一个新的单独文件夹。

For debugging purpose I'd try to isolate and identify where the error is, commenting and playing around some plugins to identify which is the offending one.出于调试目的,我会尝试隔离并确定错误所在,评论和播放一些插件以确定哪个是有问题的插件。

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

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