我正在按照gatsby 教程安装 algolia。完成后gatsby build
我得到
TypeError: Cannot read property 'addObjects' of undefined
Run Code Online (Sandbox Code Playgroud)
我的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
Run Code Online (Sandbox Code Playgroud)
我按照基本教程进行了最少的自定义。我究竟做错了什么?
我的github
当您指定的索引不存在时会发生这种情况。
在您的情况下,您发布的代码指定使用名为 的索引Posts
,例如:
indexName: `Posts`,
Run Code Online (Sandbox Code Playgroud)
gatsby algolia 插件会尝试找到这个索引并推送到它。如果它不存在,它会因这个相当神秘的错误而失败。
要修复它,请登录您的 Algolia 仪表板并使用该名称创建索引。