首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gatsby开发人员和Gatsby信息都返回错误

Gatsby开发人员和Gatsby信息都返回错误
EN

Stack Overflow用户
提问于 2018-12-23 01:27:47
回答 2查看 900关注 0票数 2

我不太清楚我的构建发生了什么,目前gatsby develop返回指向此文件的TypeError: Cannot read property 'allMarkdownRemark' of undefined

代码语言:javascript
复制
gatsby-node.js:19 graphql.then.results
C:/Users/Anders/sites/gatsby-netlify-cms/gatsby-node.js:19:20

在返回有关项目error The system cannot find the path specified.的信息后,gatsby info将返回

这是gatsby-node.js文件

代码语言:javascript
复制
const path = require('path')

exports.createPages = ({ graphql, actions }) => {
  const { createPage } = actions
  return new Promise((resolve, reject) => {
    graphql(`
      {
        allMarkdownRemark {
          edges {
            node {
              frontmatter {
                slug
              }
            }
          }
        }
      }
    `).then(results => {
      results.data.allMarkdownRemark.edges.forEach(({ node }) => {
        createPage({
          path: `/posts${node.frontmatter.slug}`,
          component: path.resolve('./src/components/postLayout.js'),
          context: {
            slug: node.frontmatter.slug,
          },
        })
      })
      resolve()
    })
  })
}

我不太明白发生了什么,我回滚到一分钟前工作正常的更改,现在收到这个奇怪的错误。我已经尝试升级节点,我已经尝试重新安装gatsby cli。我被卡住了。提前谢谢。

还包括我的package.json,以防不兼容

代码语言:javascript
复制
{
  "name": "gatsby-starter-default",
  "description": "Gatsby default starter",
  "version": "1.0.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "babel-plugin-styled-components": "^1.9.2",
    "gatsby": "^2.0.53",
    "gatsby-image": "^2.0.22",
    "gatsby-plugin-manifest": "^2.0.9",
    "gatsby-plugin-netlify": "^2.0.6",
    "gatsby-plugin-netlify-cms": "^3.0.9",
    "gatsby-plugin-offline": "^2.0.16",
    "gatsby-plugin-react-helmet": "^3.0.2",
    "gatsby-plugin-sharp": "^2.0.15",
    "gatsby-plugin-sitemap": "^2.0.3",
    "gatsby-plugin-styled-components": "^3.0.4",
    "gatsby-source-filesystem": "^2.0.10",
    "gatsby-transformer-remark": "^2.1.15",
    "gatsby-transformer-sharp": "^2.1.9",
    "netlify-cms": "^2.3.0",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-helmet": "^5.2.0",
    "react-spring": "^6.1.10",
    "styled-components": "^4.1.2"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "start": "npm run develop",
    "format": "prettier --write \"src/**/*.js\"",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "prettier": "^1.15.2"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  }
}

Gatsby -v返回2.4.7,我正在运行节点v10.14.2

这是我的gatsby-config文件

代码语言:javascript
复制
module.exports = {
  siteMetadata: {
    title: 'Project Name',
    content: 'your name is weird',
    siteUrl: 'https://zealous-wright-0d00e0.netlify.com',
  },
  plugins: [
    'gatsby-plugin-react-helmet',
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    'gatsby-plugin-sitemap',
    'gatsby-transformer-sharp',
    'gatsby-plugin-styled-components',
    'gatsby-plugin-sharp',
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: 'project-name',
        short_name: 'project-name',
        start_url: '/',
        background_color: '#663399',
        theme_color: '#663399',
        display: 'minimal-ui',
        icon: 'src/images/logo.png', // This path is relative to the root of the site.
      },
    },
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.app/offline
    'gatsby-plugin-offline',
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        path: `${__dirname}/src/team`,
        name: 'team',
      },
    },
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        path: `${__dirname}/src/images`,
        name: 'images',
      },
    },
    'gatsby-transformer-remark',
    'gatsby-plugin-netlify-cms',
  ],
}

我在src/team/riels-first-post.mdgatsby-source-filesystem里有一个文件

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-27 08:51:09

我有一个非常愚蠢的bug,在我的标记文件中,没有在我的代码中引用的slug属性。这是它应该看起来的样子

代码语言:javascript
复制
---
title: Riel's First post
bio: I am a monkey with a dog
slug: "test"
---
Testing
票数 4
EN

Stack Overflow用户

发布于 2018-12-26 19:42:49

您还没有发布您的gatsby-config文件,但是从错误判断,我认为您的节点文件找不到任何标记文件,这会导致未定义的results.data

在您的gatsby配置文件中,应该有一个类似以下内容的指令:

代码语言:javascript
复制
{
    resolve: `gatsby-source-filesystem`,
    options: {
        name: `posts`,
        path: `${__dirname}/static/content/collections/posts`,
    },
}

上面的代码指示gatsby在指定的路径中查找markdown文件,因此请确保您的配置中包含此指令,并且该路径至少包含一个有效的markdown文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53897865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档