Gatsby x构建时出现内容错误,Gatsby-node.js出现问题
几天后,我发现netlify出现了一个建筑错误。 我对盖茨比很陌生,所以我无法自己解决这个问题。我希望你们能帮我解决这个问题 TypeError:无法分解“boundActionCreators”的属性“createPage”,因为它未定义 Gatsby node.jsGatsby x构建时出现内容错误,Gatsby-node.js出现问题,node.js,gatsby,netlify,contentful,Node.js,Gatsby,Netlify,Contentful,几天后,我发现netlify出现了一个建筑错误。 我对盖茨比很陌生,所以我无法自己解决这个问题。我希望你们能帮我解决这个问题 TypeError:无法分解“boundActionCreators”的属性“createPage”,因为它未定义 Gatsby node.js exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => { if (stage === 'build-html') { actions.
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === 'build-html') {
actions.setWebpackConfig({
module: {
rules: [
{
test: /bad-module/,
use: loaders.null(),
},
],
},
});
}
};
exports.createPages = async ({ graphql, boundActionCreators }) => {
const path = require(`path`);
const { createPage } = boundActionCreators;
return new Promise((resolve, reject) => {
graphql(`
{
allContentfulProduct {
edges {
node {
id
slug
name
introTitle
description2title
description1title
category {
name
slug
}
introDescription {
internal {
content
}
}
image {
file {
url
}
}
images {
id
file {
url
}
}
description1 {
internal {
content
}
}
description2 {
internal {
content
}
}
specs
pdf {
file {
url
}
}
}
}
}
}
`).then((result) => {
result.data.allContentfulProduct.edges.forEach(({ node }) => {
createPage({
path: `systems/producten/${node.slug}`,
component: path.resolve(`./src/pages/systems/producten/product.js`),
context: {
slug: node.slug,
product: node,
},
});
});
resolve();
});
}).catch((error) => {
console.log(error);
reject();
});
};
这是构建时的错误
您正在以“老式”的方式分解结构。将其更改为:
exports.createPages = async ({ graphql, actions }) => {
const path = require(`path`);
const { createPage } = actions;
return new Promise((resolve, reject) => {
graphql(`
{
allContentfulProduct {
edges {
node {
id
slug
name
introTitle
description2title
description1title
category {
name
slug
}
introDescription {
internal {
content
}
}
image {
file {
url
}
}
images {
id
file {
url
}
}
description1 {
internal {
content
}
}
description2 {
internal {
content
}
}
specs
pdf {
file {
url
}
}
}
}
}
}
`).then((result) => {
result.data.allContentfulProduct.edges.forEach(({ node }) => {
createPage({
path: `systems/producten/${node.slug}`,
component: path.resolve(`./src/pages/systems/producten/product.js`),
context: {
slug: node.slug,
product: node,
},
});
});
resolve();
});
}).catch((error) => {
console.log(error);
reject();
});
};
只需通过actions
更改boundActionCreators
就可以在第2版以后的版本中实现这一功能,如中所示
除此之外,在您的
gatsby node.js
中,您还有:
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === 'build-html') {
actions.setWebpackConfig({
module: {
rules: [
{
test: /bad-module/,
use: loaders.null(),
},
],
},
});
}
};
/bad module/
是节点_modules
内文件夹的名称,其中包含当第三个依赖项模块在SSR中使用窗口
(或其他全局对象)时中断编译的违规模块。它是一个正则表达式,这就是为什么它位于斜杠(/
)之间,并且它应该与某个文件夹匹配,否则,您可以删除它
关于新问题,它与以前的解决方法无关。新问题是由未定义的属性引起的。如果您的数据可能是未定义的
或空的
,请添加如下条件:
{category && <span>{category.name}</span>}
{category&&{category.name}
Hi Ferran,是的,这确实是问题所在,gracias por eso!但现在我有另一个建筑问题。@VictorAforga更新。这与上一期无关。在将项目推送到Netlify之前,尝试在本地构建项目。此错误也应该出现在本地。