我的Gatsby项目中的“ReferenceError:path未定义”

问题描述 投票:0回答:1

背景

我试图按照gatsby-plugin-categories的说明安装https://www.gatsbyjs.org/packages/gatsby-plugin-categories/,但是他们要么缺少步骤,要么我的代码中有一些冲突或缺失的东西。


盖茨比-配置-JS

module.exports = {
  siteMetadata: {
    title: `VLLG`,
    description: `Village | California Campsites.`,
    author: `Juan Gallardo`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `pages`,
        path: `${__dirname}/src/pages/`,
      },
    },
    {
      resolve: "gatsby-plugin-categories",
      options: {
        templatePath: path.join(__dirname, "/src/templates/category.js")
      }
    },
    {
    resolve: `gatsby-transformer-remark`,
    options: {
      // CommonMark mode (default: true)
      commonmark: true,
      // Footnotes mode (default: true)
      footnotes: true,
      // Pedantic mode (default: true)
      pedantic: true,
      // GitHub Flavored Markdown mode (default: true)
      gfm: true,
      // Plugins configs
      plugins: [],
    },
  },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `VLLG`,
        short_name: `vllg`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
  ],
}

SRC /模板/ category.js

import React from "react";
import Helmet from "react-helmet";
import { graphql } from "gatsby";
import Layout from "../layout";
import PostListing from "../components/PostListing";

export default class CategoryTemplate extends React.Component {
  render() {
    const { pageContext, data } = this.props;
    const { category } = pageContext;
    return (
      <Layout>
        <div className="category-container">
          <Helmet title={`Posts in category "${category}"`} />
          <PostListing postEdges={data.allMarkdownRemark.edges} />
        </div>
      </Layout>
    );
  }
}

export const pageQuery = graphql`
  query CategoryPage($category: String) {
    allMarkdownRemark(
      limit: 1000
      filter: { fields: { category: { eq: $category } } }
    ) {
      totalCount
      edges {
        node {
          fields {
            slug
            category
          }
          excerpt
          timeToRead
          frontmatter {
            title
            tags
            date
          }
        }
      }
    }
  }
`;

他们有一行让我感到困惑,import PostListing from "../components/PostListing";他们从来没有给出样本代码。并且没有起动器具有那里的东西

enter image description here

不确定该解决方案是否存在于该文件中,或者我是否需要在配置中调整某些内容。

reactjs gatsby
1个回答
0
投票

你能尝试其他的路吗?

{
  resolve: "gatsby-plugin-categories",
  options: {
    templatePath: `${__dirname}/src/templates/category.js`
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.