当我尝试使用gatsby节点api文档中的createPage代码创建博客页面时,总是出现此错误。
这是我的代码
module.exports.createPages = async ({ graphql, actions }) => {
const {createPages} = actions
const blogTemplates = path.resolve('./src/templates/blogTemplates.js')
const res = await graphql (`
query{
allMarkdownRemark{
edges{
node{
fields{
slug
}
}
}
}
}
`,
res.data.allMarkdownRemark.edges.forEach((edge) => {
createPage ({
component: blogTemplates,
path: `/blog/${edge.node.fields.slug}`,
context: {
slug: edge.node.fields.slug
}
})
})
)}
这是我收到的错误消息:
错误#11321插件
“ gatsby-node.js”在运行createPages生命周期时抛出错误:
allMarkdownRemark未定义
ReferenceError:未定义allMarkdownRemark
gatsby-node.js:35 Object.module.exports.createPages C:/ Users / Mr Prewsh / Desktop / gatsby-bootcamp / gatsby-node.js:35:5
api-runner-node.js:235 runAPI [gatsby-bootcamp] / [gatsby] /dist/utils/api-runner-node.js:235:41
api-runner-node.js:375 Promise.catch.pluginName [gatsby-bootcamp] / [gatsby] /dist/utils/api-runner-node.js:375:13
新承诺
api-runner-node.js:374 runPlugin [gatsby-bootcamp] / [gatsby] /dist/utils/api-runner-node.js:374:10
api-runner-node.js:328 module.exports [gatsby-bootcamp] / [gatsby] /dist/utils/api-runner-node.js:328:24
index.js:437 module.exports [gatsby-bootcamp] / [gatsby] /dist/bootstrap/index.js:437:9
develop.js:420异步模块.exports [gatsby-bootcamp] / [gatsby] /dist/commands/develop.js:420:7
创建页面失败-0.506秒
下面是我的gatsby配置文件
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
}),
module.exports = {
/* Your site config here */
// plugins: [
// 'gatsby-plugin-sass'
// ]
siteMetadata: {
title: 'My Gatsbysite',
author: 'Mr Prewsh'
},
plugins: [
{
resolve: `gatsby-plugin-sass`,
options: {
cssLoaderOptions: {
camelCase: false,
},
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `src`,
path: `${__dirname}/src/`,
},
},
{
resolve: `gatsby-transformer-remark`,
},
]
}