【发布时间】:2021-07-25 17:26:57
【问题描述】:
几天后,我在使用 netlify 时遇到了构建错误。 我对 Gatbsy 很陌生,所以我无法自己解决它。我希望你们能帮助我解决这个问题。
TypeError:无法解构“boundActionCreators”的属性“createPage”,因为它是未定义的。
Gatsby-node.js
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();
});
};
【问题讨论】:
标签: node.js gatsby netlify contentful