我正在遵循gatsby tutorial来安装algolia。完成gatsby build
之后,我得到
TypeError: Cannot read property 'addObjects' of undefined
我的src/utils/algolia.js
文件
const postQuery = `{
posts: allMarkdownRemark(
filter: { fileAbsolutePath: { regex: "/content/" } }
) {
edges {
node {
objectID: id
frontmatter {
title
date(formatString: "DD MMMM, YYYY")
}
excerpt(pruneLength: 5000)
}
}
}
}`
const flatten = arr =>
arr.map(({ node: { frontmatter, ...rest } }) => ({
...frontmatter,
...rest,
}))
const settings = { attributesToSnippet: [`excerpt:20`] }
const queries = [
{
query: postQuery,
transformer: ({ data }) => flatten(data.posts.edges),
indexName: `Posts`,
settings,
},
]
module.exports = queries
我按照基本教程进行了最少的自定义。我究竟做错了什么?
我的github
答案 0 :(得分:3)
当您指定的索引不存在时会发生这种情况。
在您的情况下,您发布的代码指定使用名为while(c!=2):
c=int(input("Enter operation\n1.Insert beg\n2.Exit\n"))
if c == 1:
some code
的索引,例如:
Posts
gatsby algolia插件将尝试找到该索引并将其推入。如果不存在,它将失败,并显示一个相当神秘的错误。
为了进行修复,请登录到Algolia仪表板并使用该名称创建索引。