allMarkdownRemark没有返回任何结果

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

allMarkdownRemark does not return any results

问题

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

  1. {
  2. allMarkdownRemark {
  3. edges {
  4. node {
  5. id
  6. }
  7. }
  8. }
  9. }

这是它返回的内容:

  1. {
  2. "data": {
  3. "allMarkdownRemark": {
  4. "edges": []
  5. }
  6. }
  7. }

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

  1. module.exports = {
  2. siteMetadata: {
  3. title: 'Pandas Eating Lots',
  4. },
  5. plugins: [
  6. {
  7. resolve: `gatsby-source-filesystem`,
  8. options: {
  9. name: `src`,
  10. path: `${__dirname}/src`,
  11. },
  12. },
  13. `gatsby-transformer-remark`,
  14. `gatsby-plugin-emotion`,
  15. {
  16. resolve: `gatsby-plugin-typography`,
  17. options: {
  18. pathToConfigModule: `src/utils/typography`,
  19. },
  20. },
  21. ],
  22. }

这是我的package.json文件:

  1. {
  2. "name": "gatsby-starter-hello-world",
  3. "private": true,
  4. "description": "A simplified bare-bones starter for Gatsby",
  5. "version": "0.1.0",
  6. "license": "MIT",
  7. "scripts": {
  8. "build": "gatsby build",
  9. "develop": "gatsby develop",
  10. "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
  11. "start": "npm run develop",
  12. "serve": "gatsby serve",
  13. "clean": "gatsby clean",
  14. "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  15. },
  16. "dependencies": {
  17. "@emotion/core": "^10.0.27",
  18. "gatsby": "^2.18.12",
  19. "gatsby-plugin-emotion": "^4.1.18",
  20. "gatsby-plugin-typography": "^2.3.20",
  21. "gatsby-source-filesystem": "^2.1.43",
  22. "gatsby-transformer-remark": "^2.6.45",
  23. "react": "^16.12.0",
  24. "react-dom": "^16.12.0",
  25. "react-typography": "^0.16.19",
  26. "typography": "^0.16.19",
  27. "typography-theme-kirkham": "^0.16.19"
  28. },
  29. "devDependencies": {
  30. "prettier": "^1.19.1"
  31. },
  32. "repository": {
  33. "type": "git",
  34. "url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
  35. },
  36. "bugs": {
  37. "url": "https://github.com/gatsbyjs/gatsby/issues"
  38. }
  39. }

这是我的文件结构:

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:

  1. {
  2. allMarkdownRemark {
  3. edges {
  4. node {
  5. id
  6. }
  7. }
  8. }
  9. }

and this is what it returns:

  1. {
  2. "data": {
  3. "allMarkdownRemark": {
  4. "edges": []
  5. }
  6. }
  7. }

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

  1. module.exports = {
  2. siteMetadata: {
  3. title: 'Pandas Eating Lots',
  4. },
  5. plugins: [
  6. {
  7. resolve: `gatsby-source-filesystem`,
  8. options: {
  9. name: `src`,
  10. path: `${__dirname}/src`,
  11. },
  12. },
  13. `gatsby-transformer-remark`,
  14. `gatsby-plugin-emotion`,
  15. {
  16. resolve: `gatsby-plugin-typography`,
  17. options: {
  18. pathToConfigModule: `src/utils/typography`,
  19. },
  20. },
  21. ],
  22. }

this is my package.json:

  1. {
  2. "name": "gatsby-starter-hello-world",
  3. "private": true,
  4. "description": "A simplified bare-bones starter for Gatsby",
  5. "version": "0.1.0",
  6. "license": "MIT",
  7. "scripts": {
  8. "build": "gatsby build",
  9. "develop": "gatsby develop",
  10. "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
  11. "start": "npm run develop",
  12. "serve": "gatsby serve",
  13. "clean": "gatsby clean",
  14. "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  15. },
  16. "dependencies": {
  17. "@emotion/core": "^10.0.27",
  18. "gatsby": "^2.18.12",
  19. "gatsby-plugin-emotion": "^4.1.18",
  20. "gatsby-plugin-typography": "^2.3.20",
  21. "gatsby-source-filesystem": "^2.1.43",
  22. "gatsby-transformer-remark": "^2.6.45",
  23. "react": "^16.12.0",
  24. "react-dom": "^16.12.0",
  25. "react-typography": "^0.16.19",
  26. "typography": "^0.16.19",
  27. "typography-theme-kirkham": "^0.16.19"
  28. },
  29. "devDependencies": {
  30. "prettier": "^1.19.1"
  31. },
  32. "repository": {
  33. "type": "git",
  34. "url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
  35. },
  36. "bugs": {
  37. "url": "https://github.com/gatsbyjs/gatsby/issues"
  38. }
  39. }

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:

确定