我正在按照gatsby tutorial安装算法。完成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
当您指定的索引不存在时,会发生这种情况。
在您的情况下,您发布的代码指定使用名为Posts
的索引,例如:
indexName: `Posts`,
gatsby algolia插件将尝试找到该索引并将其推送。如果它不存在,它将失败,并显示此相当神秘的错误。
为了修复它,登录到您的Algolia仪表板并使用该名称创建索引。