ERROR #11321 - Gatsby Plugin Local Search - Query Returns Undefined #29949
-
I'm trying to implement search functionality using the gatsby-plugin-local-search. When I add the query to the query line in "gatsby-plugin-local-search" threw an error while running the createPages lifecycle:
Cannot read property 'nodes' of undefined gatsby-config.js module.exports = {
siteMetadata: {
title: `blahtitle`,
author: {
name: `Anonymous Author`,
summary: `blah blah lorem ipsum`,
},
description: `A blog discussing lorem ipsum.`,
siteUrl: `https://gatsby-starter-blog-demo.netlify.app/`,
social: {
twitter: `Software Site`,
},
},
plugins: [
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content/blog`,
name: `blog`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content/assets`,
name: `assets`,
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 630,
},
},
{
resolve: `gatsby-remark-responsive-iframe`,
options: {
wrapperStyle: `margin-bottom: 1.0725rem`,
},
},
`gatsby-remark-prismjs`,
`gatsby-remark-copy-linked-files`,
`gatsby-remark-smartypants`,
],
},
},
{
resolve: `gatsby-plugin-google-analytics`,
options: {
//trackingId: `ADD YOUR TRACKING ID HERE`,
},
},
`gatsby-plugin-feed`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `SoftwareSite`,
short_name: `SoftwareSite`,
start_url: `/`,
background_color: `#ffffff`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `content/assets/gatsby-icon.png`,
},
},
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-plugin-local-search`,
options: {
name: `pages`,
engine: `flexsearch`,
query: `{
allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) {
nodes {
excerpt
fields {
slug
}
frontmatter {
date(formatString: "MMMM DD, YYYY")
title
description
}
}
}
}`,
ref: `slug`,
index: [`title`, `excerpt`],
store: [`title`, `excerpt`, `date`, `slug`],
normalizer: ({ data }) =>
data.allMarkDownRemark.nodes.map(post => ({
title: post.frontmatter.title,
excerpt: post.excerpt,
date: post.frontmatter.date,
slug: post.fields.slug,
})),
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
} This query works however in both GraphiQL and in my query that I use in my index.js. (I'm trying to search for blog posts, so it is the same). Here's an attached image of it working on GraphiQL. Obviously, it should be returning some nodes as the same query works in both GraphiQl and in my index.js file. However, maybe I'm just missing something and was wondering if anyone else has had a similar issue. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In your line For specific help with the plugin it's best to contact the author of the plugin itself as we don't maintain this plugin here :) |
Beta Was this translation helpful? Give feedback.
In your line
data.allMarkDownRemark.nodes.map
it should bedata.allMarkdownRemark.nodes.map
.For specific help with the plugin it's best to contact the author of the plugin itself as we don't maintain this plugin here :)