allMarkdownRemark没有返回任何结果

huangapple go评论84阅读模式
英文:

allMarkdownRemark does not return any results

问题

我正在尝试完成Transformer插件教程的第6部分(链接)。我在src目录中创建了一个.md文件。我使用GraphiQL并运行了以下代码:

{
  allMarkdownRemark {
    edges {
      node {
        id
      }
    }
  }
}

这是它返回的内容:

{
  "data": {
    "allMarkdownRemark": {
      "edges": []
    }
  }
}

尽管我在src目录中有一个.md文件。这是我的gatsby-config.js文件:

module.exports = {
  siteMetadata: {
    title: 'Pandas Eating Lots',
  },
  plugins: [
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `src`,
        path: `${__dirname}/src`,
      },
    },
    `gatsby-transformer-remark`,
    `gatsby-plugin-emotion`,
    {
      resolve: `gatsby-plugin-typography`,
      options: {
        pathToConfigModule: `src/utils/typography`,
      },
    },
  ],
}

这是我的package.json文件:

{
  "name": "gatsby-starter-hello-world",
  "private": true,
  "description": "A simplified bare-bones starter for Gatsby",
  "version": "0.1.0",
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "dependencies": {
    "@emotion/core": "^10.0.27",
    "gatsby": "^2.18.12",
    "gatsby-plugin-emotion": "^4.1.18",
    "gatsby-plugin-typography": "^2.3.20",
    "gatsby-source-filesystem": "^2.1.43",
    "gatsby-transformer-remark": "^2.6.45",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-typography": "^0.16.19",
    "typography": "^0.16.19",
    "typography-theme-kirkham": "^0.16.19"
  },
  "devDependencies": {
    "prettier": "^1.19.1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

这是我的文件结构:

allMarkdownRemark没有返回任何结果

我会感激任何人能帮助我弄清楚发生了什么。

英文:

I am trying to do part 6 of the tutorial on Transformer plugins (link). I created a .md file in the src directory. I used GraphiQL and ran the following:

{
  allMarkdownRemark {
    edges {
      node {
        id
      }
    }
  }
}

and this is what it returns:

{
  "data": {
    "allMarkdownRemark": {
      "edges": []
    }
  }
}

Even though I have a .md file in the src directory. Here is my gatsby-config.js file:

module.exports = {
  siteMetadata: {
    title: 'Pandas Eating Lots',
  },
  plugins: [
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `src`,
        path: `${__dirname}/src`,
      },
    },
    `gatsby-transformer-remark`,
    `gatsby-plugin-emotion`,
    {
      resolve: `gatsby-plugin-typography`,
      options: {
        pathToConfigModule: `src/utils/typography`,
      },
    },
  ],
}

this is my package.json:

{
  "name": "gatsby-starter-hello-world",
  "private": true,
  "description": "A simplified bare-bones starter for Gatsby",
  "version": "0.1.0",
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "dependencies": {
    "@emotion/core": "^10.0.27",
    "gatsby": "^2.18.12",
    "gatsby-plugin-emotion": "^4.1.18",
    "gatsby-plugin-typography": "^2.3.20",
    "gatsby-source-filesystem": "^2.1.43",
    "gatsby-transformer-remark": "^2.6.45",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-typography": "^0.16.19",
    "typography": "^0.16.19",
    "typography-theme-kirkham": "^0.16.19"
  },
  "devDependencies": {
    "prettier": "^1.19.1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

and this is my file structure:

allMarkdownRemark没有返回任何结果

I would appreciate if anyone could help me figure out what is going on.

答案1

得分: 2

你的“文件结构”看起来像是VS Code。Markdown文件的图标是错误的,所以我认为你是从教程中复制文件名然后通过复制/粘贴输入的。但是:文件名末尾有一个空格,因此它被识别为具有“ .md ”扩展名的文件(而不是空格)。重命名它,你将在VS Code中看到正确的Markdown图标,并且文件将被正确检测。

英文:

your "file structure" looks like vscode. The icon for the markdown file is wrong, so i think you copied the name of the file from the tutorial and entered it via copy/paste. BUT: the filename has a blank at the end, and so this is not recognized as a markdown file but as a file with an ".md " extension (not the blank). rename it and you will see a correct markdown-icon in vscode and the file will be detected

答案2

得分: 0

我已经在 gatsby-config.js 中更改了插件的顺序,将 gatsby-transformer-remark 放在第一位。这对我起到了作用。

英文:

I have changed the order of plugins at gatsby-config.js, putting gatsby-transformer-remark first. It's worked for me.

huangapple
  • 本文由 发表于 2020年1月3日 19:32:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577880.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定