Gatsby 将盖茨比博客部署到Netlify时出错

Gatsby 将盖茨比博客部署到Netlify时出错,gatsby,netlify,contentful,Gatsby,Netlify,Contentful,我在Netlify上部署了我的盖茨比博客,但遇到了几个问题 问题 -当我运行“盖茨比开发”时,我可以看到博客文章,即使有错误消息。 -但是,当我运行“gatsby build”时,错误停止处理。 -我成功地部署并删除了“gatsby node.js”中的内容。 -我可以看到已部署的网页,但不知何故,通过Contentful管理的博客帖子不起作用。 -若我使用“gatsby node.js”中的内容进行部署,它将失败并且无法工作 观察 -因为“gatsby node.js”是用于帖子创建的,这会影

我在Netlify上部署了我的盖茨比博客,但遇到了几个问题

问题 -当我运行“盖茨比开发”时,我可以看到博客文章,即使有错误消息。 -但是,当我运行“gatsby build”时,错误停止处理。 -我成功地部署并删除了“gatsby node.js”中的内容。 -我可以看到已部署的网页,但不知何故,通过Contentful管理的博客帖子不起作用。 -若我使用“gatsby node.js”中的内容进行部署,它将失败并且无法工作

观察 -因为“gatsby node.js”是用于帖子创建的,这会影响我的博客页面。 -如果我保持原样,它将返回一条错误消息,说明“TypeError:无法读取未定义的属性'replace'。 -相信这不是一个令人满意的问题,因为我可以通过开发环境看到所有的帖子

预期结果 -在网页上显示帖子

如果您能分享您的想法/想法以解决此问题,我们将不胜感激

const config=require('./src/utils/siteConfig')
const path=require(`path`)
const{createFilePath}=require('gatsby-source-filesystem');
exports.onCreateNode=({node,boundActionCreators,getNode})=>{
const{createNodeField}=boundActionCreators;
if(node.internal.type==`MarkdownRemark`){
const value=createFilePath({node,getNode});
createNodeField({
名称:`slug`,
节点,
价值
});
}
};
exports.createPages=({graphql,actions})=>{
const{createPage}=actions
const loadPosts=新承诺((解决、拒绝)=>{
图形ql(`
{
allContentfulPost(
排序:{字段:[publishDate],顺序:DESC}
限额:10000
) {
边缘{
节点{
鼻涕虫
出版日期
}
}
}
}
`)。然后(结果=>{
const posts=result.data.allContentfulPost.edges
const postsPerFirstPage=config.postsPerHomePage
const postsPerPage=config.postsPerPage
const numPages=Math.ceil(
posts.slice(postsPerFirstPage).length/postsPerPage
)
//创建主主页
创建页面({
路径:`/`,
组件:path.resolve(`./src/templates/index.js`),
背景:{
限值:postsPerFirstPage,
跳过:0,
numPages:numPages+1,
当前页面:1,
},
})
//如果需要,在主页上创建其他分页
Array.from({length:numPages}).forEach((\ux,i)=>{
创建页面({
路径:`/${i+2}/`,
组件:path.resolve(`./src/templates/index.js`),
背景:{
限制:postsPerPage,
跳过:i*postsPerPage+postsPerFirstPage,
numPages:numPages+1,
当前页面:i+2,
},
})
})
//创建每个单独的帖子
posts.forEach((边缘,i)=>{
const prev=i==0?null:posts[i-1]。节点
const next=i==posts.length-1?null:posts[i+1]。节点
创建页面({
路径:`${edge.node.slug}/`,
组件:path.resolve(`./src/templates/post.js`),
背景:{
slug:edge.node.slug,
前,
下一个
},
})
})
解决()
})
})
const loadTags=新承诺((解决、拒绝)=>{
图形ql(`
{
所有内容标签{
边缘{
节点{
鼻涕虫
职位{
身份证件
}
}
}
}
}
`)。然后(结果=>{
const tags=result.data.allContentfulTag.edges
const postsPerPage=config.postsPerPage
//如果需要,创建带有分页的标记页
tags.map(({node})=>{
const totalPosts=node.post!==null?node.post.length:0
const numPages=Math.ceil(totalPosts/postsPerPage)
Array.from({length:numPages}).forEach((\ux,i)=>{
创建页面({
路径:
i===0?`/tag/${node.slug}/`:`/tag/${node.slug}/${i+1}/`,
组件:path.resolve(`./src/templates/tag.js`),
背景:{
slug:node.slug,
限制:postsPerPage,
跳过:我*后页,
numPages:numPages,
当前页面:i+1,
},
})
})
})
解决()
})
})
const loadPages=新承诺((解决、拒绝)=>{
图形ql(`
{
allContentfulPage{
边缘{
节点{
鼻涕虫
}
}
}
}
`)。然后(结果=>{
const pages=result.data.allContentfulPage.edges
pages.map(({node})=>{
创建页面({
路径:`${node.slug}/`,
组件:path.resolve(`./src/templates/page.js`),
背景:{
slug:node.slug,
},
})
})
解决()
})
})
返回承诺。全部([LoadPost、loadTags、loadPages])

}
局外人很难调试您的代码

我建议删除代码:

  • 从gatsby-node.js中删除所有代码
  • 将代码添加到
    gatsby node.js
    并构建项目,直到遇到错误
  • 这很费时,但可能是必要的。那至少你知道罪魁祸首是什么
提示您的
gatsby config.js
也可能有问题。仔细检查您的盖茨比源文件系统插件

  - utils.js:71 slash
    [smy.jp]/[gatsby-source-filesystem]/utils.js:71:15

  - create-file-path.js:40 module.exports
    /[gatsby-source-filesystem]/create-file-path.js:40:61